Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/master' into feature/add…
Browse files Browse the repository at this point in the history
…_jacoco_support

# Conflicts:
#	README.md
#	balta/src/main/scala/za/co/absa/db/balta/classes/setter/SetterFnc.scala
#	build.sbt
  • Loading branch information
benedeki committed Sep 29, 2024
2 parents ad1c885 + a63dc25 commit e0c8046
Show file tree
Hide file tree
Showing 39 changed files with 1,148 additions and 278 deletions.
36 changes: 36 additions & 0 deletions .github/ISSUE_TEMPLATE/spike_task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: Spike
about: Issue template for spikes, research and investigation tasks
labels: 'spike'

---

## Background
A clear and concise description of the problem or a topic we need to understand.

Feel free to add information about why it's needed and what assumptions you have at the moment.

## Questions To Answer

1.
2.
3.

## Desired Outcome

The list of desired outcomes of this spike ticket.

```[tasklist]
### Tasks
- [ ] Questions have been answered or we have a clearer idea of how to get to our goal
- [ ] Discussion with the team
- [ ] Documentation
- [ ] Create recommendations and new implementation tickets
- [ ] item here..
```

## Additional Info/Resources [Optional]

1.
2.
3.
31 changes: 30 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,42 @@ jobs:

name: Scala ${{matrix.scala}}

services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: mag_db
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Checkout code
uses: actions/checkout@v4

- uses: coursier/cache-action@v5

- name: Setup Scala
uses: olafurpg/setup-scala@v10
with:
java-version: "adopt@1.8"
- name: Build and run tests

- name: Build and run unit tests
run: sbt ++${{matrix.scala}} test doc

- name: Setup database
run: |
psql postgresql://postgres:postgres@localhost:5432/mag_db -f balta/src/test/resources/db/postgres/02_users.ddl
psql postgresql://postgres:postgres@localhost:5432/mag_db -f balta/src/test/resources/db/postgres/03_schema_testing.ddl
psql postgresql://postgres:postgres@localhost:5432/mag_db -f balta/src/test/resources/db/postgres/04_testing.base_types.ddl
psql postgresql://postgres:postgres@localhost:5432/mag_db -f balta/src/test/resources/db/postgres/05_testing._base_types_data.sql
psql postgresql://postgres:postgres@localhost:5432/mag_db -f balta/src/test/resources/db/postgres/06_testing.pg_types.ddl
psql postgresql://postgres:postgres@localhost:5432/mag_db -f balta/src/test/resources/db/postgres/07_testing_pg_types_data.sql
- name: Build and run integration tests
run: sbt ++${{matrix.scala}} testIT
41 changes: 0 additions & 41 deletions .github/workflows/ci-check-jacoco.yml

This file was deleted.

119 changes: 119 additions & 0 deletions .github/workflows/jacoco_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: CI check JaCoCo code-coverage

on:
pull_request:
branches: [ master ]

env:
scalaLong: 2.12.18
scalaShort: "2.12"
coverage-overall: 0.0
coverage-changed-files: 0.0
check-overall-coverages: true

jobs:
build-test-and-measure:
name: Build, Test and Measure
runs-on: ubuntu-latest

services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: mag_db
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Scala
uses: olafurpg/setup-scala@v10
with:
java-version: "adopt@1.8"

- name: Setup database
run: |
psql postgresql://postgres:postgres@localhost:5432/mag_db -f balta/src/test/resources/db/postgres/02_users.ddl
psql postgresql://postgres:postgres@localhost:5432/mag_db -f balta/src/test/resources/db/postgres/03_schema_testing.ddl
psql postgresql://postgres:postgres@localhost:5432/mag_db -f balta/src/test/resources/db/postgres/04_testing.base_types.ddl
psql postgresql://postgres:postgres@localhost:5432/mag_db -f balta/src/test/resources/db/postgres/05_testing._base_types_data.sql
psql postgresql://postgres:postgres@localhost:5432/mag_db -f balta/src/test/resources/db/postgres/06_testing.pg_types.ddl
psql postgresql://postgres:postgres@localhost:5432/mag_db -f balta/src/test/resources/db/postgres/07_testing_pg_types_data.sql
- name: Build and run tests
continue-on-error: true
id: jacocorun
run: sbt jacoco

- name: Add coverage to PR
if: steps.jacocorun.outcome == 'success'
id: jacoco-balta
uses: madrapps/jacoco-report@v1.7.1
with:
paths: ${{ github.workspace }}/balta/target/scala-${{ env.scalaShort }}/jacoco/report/jacoco.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: ${{ env.coverage-overall }}
min-coverage-changed-files: ${{ env.coverage-changed-files }}
title: JaCoCo 'balta' module code coverage report - scala ${{ env.scalaLong }}
update-comment: true
- name: Get the Coverage info
if: steps.jacocorun.outcome == 'success'
run: |
echo "Total 'balta' module coverage ${{ steps.jacoco-balta.outputs.coverage-overall }}"
echo "Changed Files coverage ${{ steps.jacoco-balta.outputs.coverage-changed-files }}"
- name: Fail PR if changed files coverage is less than ${{ env.coverage-changed-files }}%
if: steps.jacocorun.outcome == 'success'
uses: actions/github-script@v6
with:
script: |
const coverageCheckFailed =
Number('${{ steps.jacoco-balta.outputs.coverage-changed-files }}') < Number('${{ env.coverage-changed-files }}')
if (coverageCheckFailed) {
core.setFailed('Changed files coverage is less than ${{ env.coverage-changed-files }}%!');
}
- name: Fail PR if overall files coverage is less than ${{ env.coverage-overall }}%
if: ${{ (steps.jacocorun.outcome == 'success') && (env.check-overall-coverages == 'true') }}
uses: actions/github-script@v6
with:
script: |
const coverageCheckFailed =
Number('${{ steps.jacoco-balta.outputs.coverage-overall }}') < Number('${{ env.coverage-overall }}');
if (coverageCheckFailed) {
core.setFailed('Overall coverage is less than ${{ env.coverage-overall }}%!');
}
- name: Edit JaCoCo comments on build failure
if: steps.jacocorun.outcome != 'success'
uses: actions/github-script@v6
with:
script: |
const issue_number = context.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
const jacocoReportRegExp = /^### JaCoCo .* code coverage report .*/;
const comments = await github.rest.issues.listComments({
owner,
repo,
issue_number,
});
for (const comment of comments.data) {
const lines = comment.body.split('\n');
if (lines.length > 0 && jacocoReportRegExp.test(lines[0])) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: comment.id,
body: lines[0] + "\n\n### Build Failed",
});
}
}
core.setFailed('JaCoCo test coverage report generation failed, and related PR comments were updated.');
41 changes: 41 additions & 0 deletions .github/workflows/test_filenames_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Copyright 2023 ABSA Group Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

name: Test Filenames Check

on:
pull_request:
branches: [ master ]
types: [ opened, synchronize, reopened ]

jobs:
test_filenames_check:
name: Test Filenames Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Filename Inspector
id: scan-test-files
uses: AbsaOSS/filename-inspector@v0.1.0
with:
name-patterns: '*UnitTests.*,*IntegrationTests.*'
paths: '**/src/test/scala/**'
report-format: 'console'
excludes: 'balta/src/test/scala/za/co/absa/db/balta/testing/*'
verbose-logging: 'false'
fail-on-violation: 'true'
27 changes: 27 additions & 0 deletions .sbtrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Copyright 2023 ABSA Group Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Aliases in this file expected usage of test file naming conventions:
# - "UnitTests" suffix for test files and Suites which define unit tests
# - "IntegrationTests" suffix for test files and Suites which define integration tests

# CPS QA types aliases
# * Unit tests
alias test=; testOnly *UnitTests

# * Integration tests
alias testIT=; testOnly *IntegrationTests

38 changes: 33 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# Balta

Scala library to write Postgres DB code tests with
Balta 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).

---

### Build Status

[![Build](https://github.com/AbsaOSS/balta/workflows/Build/badge.svg)](https://github.com/AbsaOSS/balta/actions)

[![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)

---

Balta is a Scala library to help creating database tests, particularly testing Database functions. It is based on the
popular [ScalaTest](http://www.scalatest.org/) library and uses [PostgreSQL](https://www.postgresql.org/) as the
database engine.
popular [ScalaTest](http://www.scalatest.org/) library and uses [PostgreSQL](https://www.postgresql.org/) as the database engine.

It's a natural complement to the use of [Fa-Db library](https://github.com/AbsaOSS/fa-db) in applications.

Expand All @@ -21,13 +30,32 @@ It's a natural complement to the use of [Fa-Db library](https://github.com/AbsaO
Advantages of this approach is that the tests repeateble, they are isolated from each other and the database is always
in a known state before and after each test.

## How to generate JaCoCo code coverage report
Run command from path `{project-root}`
## How to Test
There are integration tests part of the package that can be run with the following command:

```bash
sbt testIT
```

The tests to finish successfully, a Postgres database must be running and populated.
* by default the database is expected to be running on `localhost:5432`
* if you wish to run against a different server modify the `src/test/resources/database.properties` file
* to populate the database run the scripts in the `src/test/resources/db/postgres` folder

## How to generate JaCoCo code coverage report

Run the following command from path `{project-root}`
```bash
sbt jacoco
```
Report should be available on path `{project-root}/balta/target/scala-2.12/jacoco/report/html`


## How to Release

Please see [this file](RELEASE.md) for more details.

## Known Issues

### Postgres
* `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
Loading

0 comments on commit e0c8046

Please sign in to comment.