Skip to content

Commit

Permalink
test: add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Jaime Silvela <jaime.silvela@enterprisedb.com>
  • Loading branch information
jsilvela committed Apr 11, 2023
1 parent 5562d24 commit ad75837
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/unit-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
on: [push]

jobs:
plain_test:
runs-on: ubuntu-latest
name: Unit test
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: python -m pip install --upgrade pip prettytable
- name: Run suite
run: python test_summary.py -v
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# editor and IDE paraphernalia
.idea
__pycache__/
8 changes: 8 additions & 0 deletions DEVELOPERS_DEVELOPERS_DEVELOPERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ act -b --env GITHUB_STEP_SUMMARY='github-summary.md'

Running this should create a file `github-summary.md` with the test summary.

## Unit tests

CIclops has the beginnig of a unit test suite. You can run it with:

``` sh
python3 -m unittest
```

## How it works

The files in this repository are needed for the Dockerfile to build and run, of
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "InitDB settings - custom default locale -- use the custom default locale specified",
"state": "passed",
"start_time": "2021-11-29T18:29:12.613387+01:00",
"end_time": "2021-11-29T18:31:07.988145+01:00",
"error": "",
"error_file": "",
"error_line": 0,
"platform": "local",
"postgres_kind": "PostgreSQL",
"matrix_id": "id1",
"postgres_version": "11.1",
"k8s_version": "22",
"workflow_id": 12,
"repo": "my-repo",
"branch": "my-branch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "InitDB settings - initdb custom post-init SQL scripts -- can find the tables created by the post-init SQL queries",
"state": "failed",
"start_time": "2021-11-29T18:28:37.198931+01:00",
"end_time": "2021-11-29T18:29:12.613157+01:00",
"error": "Expected\n <string>: 1\\n\nto equal\n <string>: 2\\n",
"error_file": "/Users/jaime.silvela/repos/cloud-native-postgresql/tests/e2e/initdb_test.go",
"error_line": 80,
"platform": "local",
"postgres_kind": "PostgreSQL",
"matrix_id": "id1",
"postgres_version": "11.1",
"k8s_version": "22",
"workflow_id": 12,
"repo": "my-repo",
"branch": "my-branch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "ignoreFails on e2e tests -- generates a failing tests that should be ignored",
"state": "ignoreFailed",
"start_time": "0001-01-01T00:00:00Z",
"end_time": "0001-01-01T00:00:00Z",
"error": "",
"error_file": "",
"error_line": 0,
"platform": "local",
"postgres_kind": "PostgreSQL",
"matrix_id": "id1",
"postgres_version": "11.1",
"k8s_version": "22",
"workflow_id": 12,
"repo": "my-repo",
"branch": "my-branch"
}
70 changes: 70 additions & 0 deletions test_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#
# Copyright The CloudNativePG Contributors
#
# 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.
#

import unittest
import summarize_test_results
import datetime


class TestIsFailed(unittest.TestCase):
def test_compute_summary(self):
self.maxDiff = None
summary = summarize_test_results.compute_test_summary("few-artifacts")
self.assertEqual(summary["total_run"], 3)
self.assertEqual(summary["total_failed"], 1)

self.assertEqual(
summary["by_code"]["total"],
{
"/Users/jaime.silvela/repos/cloud-native-postgresql/tests/e2e/initdb_test.go:80": 1
},
"unexpected summary",
)
self.assertEqual(
summary["by_code"]["tests"],
{
"/Users/jaime.silvela/repos/cloud-native-postgresql/tests/e2e/initdb_test.go:80": {
"InitDB settings - initdb custom post-init SQL scripts -- can find the tables created by the post-init SQL queries": True
}
},
"unexpected summary",
)
self.assertEqual(
summary["by_matrix"], {"total": {"id1": 3}, "failed": {"id1": 1}}
)
self.assertEqual(summary["by_k8s"], {"total": {"22": 3}, "failed": {"22": 1}})
self.assertEqual(
summary["by_platform"], {"total": {"local": 3}, "failed": {"local": 1}}
)
self.assertEqual(
summary["by_postgres"],
{"total": {"PostgreSQL-11.1": 3}, "failed": {"PostgreSQL-11.1": 1}},
)
self.assertEqual(
summary["suite_durations"],
{
"end_time": {
"local": {"id1": datetime.datetime(2021, 11, 29, 18, 31, 7)}
},
"start_time": {
"local": {"id1": datetime.datetime(2021, 11, 29, 18, 28, 37)}
},
},
)


if __name__ == "__main__":
unittest.main()

0 comments on commit ad75837

Please # to comment.