{"id":18810334,"url":"https://github.com/absaoss/balta","last_synced_at":"2025-04-13T20:30:55.849Z","repository":{"id":211460950,"uuid":"715532003","full_name":"AbsaOSS/balta","owner":"AbsaOSS","description":"Scala library to write Postgres DB code tests with","archived":false,"fork":false,"pushed_at":"2024-10-24T13:59:35.000Z","size":128,"stargazers_count":2,"open_issues_count":11,"forks_count":0,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-10-25T06:37:24.381Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AbsaOSS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-07T10:33:41.000Z","updated_at":"2024-10-23T22:17:49.000Z","dependencies_parsed_at":"2024-09-11T12:00:50.604Z","dependency_job_id":"bf948e2c-b35d-4a7c-9807-291bfa0ef8ae","html_url":"https://github.com/AbsaOSS/balta","commit_stats":null,"previous_names":["absaoss/balta"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbsaOSS%2Fbalta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbsaOSS%2Fbalta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbsaOSS%2Fbalta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbsaOSS%2Fbalta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AbsaOSS","download_url":"https://codeload.github.com/AbsaOSS/balta/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223603193,"owners_count":17172057,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T23:19:50.350Z","updated_at":"2024-11-07T23:19:50.890Z","avatar_url":"https://github.com/AbsaOSS.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Balta\n\nBalta makes testing DB entities from Scala easier. It's primarily focused on testing the behavior of [Postgres functions](https://www.postgresql.org/docs/current/xfunc.html).\n\n---\n\n### Build Status\n\n[![Build](https://github.com/AbsaOSS/balta/workflows/Build/badge.svg)](https://github.com/AbsaOSS/balta/actions)\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/za.co.absa.db/balta_2.12/badge.svg)](https://search.maven.org/search?q=g:za.co.absa.db.balta)\n\n---\n\nBalta is a Scala library to help creating database tests, particularly testing Database functions. It is based on the \npopular [ScalaTest](http://www.scalatest.org/) library and uses [PostgreSQL](https://www.postgresql.org/) as the database engine.\n\nIt's a natural complement to the use of [Fa-Db library](https://github.com/AbsaOSS/fa-db) in applications.\n\n## Expected test-case structure\n1. _Transaction start_*\n2. Insert needed data into tables\n3. Call the function to be tested\n4. Verify the return values of the function via the `verify` function provided\n5. Verify the data un the tables\n6. _Transaction rollback_*\n\n * The transaction start and rollback are done automatically before or after the execution respectively of the `test` function provided\n\nAdvantages of this approach is that the tests are repeatable, they are isolated from each other and the database is always \nin a known state before and after each test.\n\n\n## How to write tests\n\n### [`DBTestSuite`](https://github.com/AbsaOSS/balta/blob/master/balta/src/main/scala/za/co/absa/db/balta/DBTestSuite.scala) class\n\nThe foundation is the [`DBTestSuite`](https://github.com/AbsaOSS/balta/blob/master/balta/src/main/scala/za/co/absa/db/balta/DBTestSuite.scala) \nclass that provides the necessary setup and teardown for the tests to each run in its own transaction. It is an \nenhancement class to standard ScalaTest `AnyFunSuite` class.\n\nBesides that, it provides easy access to tables, queries them and inserts data into them.\n\nAnd it allows easy access to database functions and executing them.\n\n### [`DBTable`](https://github.com/AbsaOSS/balta/blob/master/balta/src/main/scala/za/co/absa/db/balta/classes/DBTable.scala) class\n\nClass for representing a database table. It provides methods for querying the table and inserting data into it. The class \ninstance is spawned by each `DBTestSuite.table` method call. \n\n### [`DBFunction`](https://github.com/AbsaOSS/balta/blob/master/balta/src/main/scala/za/co/absa/db/balta/classes/DBFunction.scala) class\n\nClass for representing a database function. It provides methods for calling the function and verifying the return values.\nThe class instance is spawned by each `DBTestSuite.function` method call.\n\n### [`QueryResult`](https://github.com/AbsaOSS/balta/blob/master/balta/src/main/scala/za/co/absa/db/balta/classes/QueryResult.scala) class\n\nThis iterator represents the result of a query. It provides methods for iterating over the rows and columns of the result.\n\n### [`QueryResultRow`](https://github.com/AbsaOSS/balta/blob/master/balta/src/main/scala/za/co/absa/db/balta/classes/QueryResultRow.scala) class\n\nThis class represents a row in a query result. It provides methods for accessing the columns of the row - via name or index.\n\nTo make specific Postgres types available in `QueryResultRow` there is the implicit class \n[`Postgres.PostgresRow`](https://github.com/AbsaOSS/balta/blob/master/balta/src/main/scala/za/co/absa/db/balta/implicits/Postgres.scala)\nenhancing the `QueryResultRow` with the ability to get type like `JSON` (including JSONB) and `JSON[]` (JSON array).\n\nThere is also an implicit class \n[`QueryResultImplicits.ProductTypeConvertor`](https://github.com/AbsaOSS/balta/blob/master/balta/src/main/scala/za/co/absa/db/balta/implicits/QueryResultImplicits.scala) \nenhancing  the `QueryResultRow` with the ability to convert the row to a product type (case class or tuple) via function\n`toProductType[T]`.\n\n\n\n\n\n## How to test the library\n\nUse the `test` command to execute all unit tests, skipping all other types of tests.\n```bash\nsbt test\n```\n\nThere are integration tests part of the package that can be run with the following command:\n```bash\nsbt testIT\n```\n\nIf you want to run all tests, use the following command.\n```bash\nsbt testAll\n```\n\nThe integrations tests to finish successfully, a Postgres database must be running and populated.\n* by default the database is expected to be running on `localhost:5432`\n* if you wish to run against a different server modify the `src/test/resources/database.properties` file\n* to populate the database run the scripts in the `src/test/resources/db/postgres` folder\n\n## How to generate JaCoCo code coverage report\n\nRun the following command from path `{project-root}`\n```bash\nsbt jacoco\n```\nReport should be available on path `{project-root}/balta/target/scala-2.12/jacoco/report/html`\n\n\n## How to Release\n\nPlease see [this file](RELEASE.md) for more details.\n\n## Known Issues\n\n### Postgres\n* `TIMESTAMP WITH TIME ZONE[]`, `TIME WITH TIME ZONE[]`, generally arrays of time related types are not translated to appropriate time zone aware Scala/Java types\n* Conversion to product type won't work if there are complex members in the product type like subclasses; with container types like `List`, it hasn't been tested ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabsaoss%2Fbalta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabsaoss%2Fbalta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabsaoss%2Fbalta/lists"}