Skip to content

Commit

Permalink
[MISC] Renovate tweaks and enable codecov (#259)
Browse files Browse the repository at this point in the history
* Renovate tweaks

* Fix indent

* Enable codecov

* Unit tests
  • Loading branch information
dragomirp authored Apr 3, 2024
1 parent b1f45ff commit e03c8ce
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 6 deletions.
10 changes: 10 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github_checks:
annotations: false
coverage:
status:
project:
default:
target: 70%
patch:
default:
target: 33%
62 changes: 61 additions & 1 deletion .github/renovate.json5
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["github>canonical/data-platform//renovate_presets/charm.json5"],
"reviewers": ["dragomirp", "marceloneppel", "taurus-forever"],
"reviewers": ["dragomirp", "lucasgameiroborges", "marceloneppel", "taurus-forever"],
"packageRules": [
// Later rules override earlier rules
{
Expand All @@ -10,6 +10,66 @@
}, {
"matchPackageNames": ["python"],
"allowedVersions": "<3.11"
},
{
"matchDepNames": ["Juju 2"],
"matchPackageNames": ["juju/juju"],
"allowedVersions": "<3.0.0",
"extractVersion": "^v(?<version>.*)$",
"groupName": "Juju 2"
},
{
"matchDepNames": ["Juju 3"],
"matchPackageNames": ["juju/juju"],
"allowedVersions": "<3.2.0",
"extractVersion": "^v(?<version>.*)$",
"groupName": "Juju 3"
},
{
"matchDepNames": ["libjuju 2"],
"matchPackageNames": ["juju"],
"matchManagers": ["regex"],
"matchDatasources": ["pypi"],
"versioning": "loose",
"allowedVersions": "<3",
"groupName": "Juju 2"
}
],
"regexManagers": [
{
"customType": "regex",
"fileMatch": ["^(workflow-templates|\\.github/workflows)/[^/]+\\.ya?ml$"],
"matchStrings": [
"(- agent: )(?<currentValue>.*?) +# renovate: latest juju 2"
],
"depNameTemplate": "Juju 2",
"packageNameTemplate": "juju/juju",
"datasourceTemplate": "github-releases",
"versioningTemplate": "loose",
"extractVersionTemplate": "Juju release"
},
{
"customType": "regex",
"fileMatch": ["^(workflow-templates|\\.github/workflows)/[^/]+\\.ya?ml$"],
"matchStrings": [
"(- agent: )(?<currentValue>.*?) +# renovate: latest juju 3"
],
"depNameTemplate": "Juju 3",
"packageNameTemplate": "juju/juju",
"datasourceTemplate": "github-releases",
"versioningTemplate": "loose",
"extractVersionTemplate": "Juju release"
},
{
"customType": "regex",
"fileMatch": ["^(workflow-templates|\\.github/workflows)/[^/]+\\.ya?ml$"],
"matchStrings": [
"(libjuju: )==(?<currentValue>.*?) +# renovate: latest libjuju 2"
],
"depNameTemplate": "libjuju 2",
"packageNameTemplate": "juju",
"datasourceTemplate": "pypi",
"versioningTemplate": "loose"
}
]
}
8 changes: 5 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
pipx install poetry
- name: Run tests
run: tox run -e unit
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3

build:
name: Build charm
Expand All @@ -49,10 +51,10 @@ jobs:
fail-fast: false
matrix:
juju:
- agent: 2.9.46
libjuju: ^2
- agent: 2.9.47 # renovate: latest juju 2
libjuju: ==2.9.46.1 # renovate: latest libjuju 2
allure: false
- agent: 3.1.7
- agent: 3.1.7 # renovate: latest juju 3
allure: true
name: Integration test charm | ${{ matrix.juju.agent }}
needs:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ build/
*.charm
.tox/
.coverage
coverage.xml
__pycache__/
*.py[cod]
*.log
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ pytest-github-secrets = {git = "https://github.com/canonical/data-platform-workf
pytest-operator = "^0.34.0"
pytest-operator-cache = {git = "https://github.com/canonical/data-platform-workflows", tag = "v13.0.0", subdirectory = "python/pytest_plugins/pytest_operator_cache"}
pytest-operator-groups = {git = "https://github.com/canonical/data-platform-workflows", tag = "v13.0.0", subdirectory = "python/pytest_plugins/pytest_operator_groups"}
juju = "^3.2.0.1"
# renovate caret doesn't work: https://github.com/renovatebot/renovate/issues/26940
juju = "<=3.4.0.0"
tenacity = "*"
psycopg2-binary = "^2.9.9"
allure-pytest = "^2.13.5"
Expand All @@ -83,6 +84,9 @@ branch = true

[tool.coverage.report]
show_missing = true
exclude_lines = [
"logger\\.debug"
]

[tool.pytest.ini_options]
minversion = "6.0"
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/relations/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from unittest.mock import Mock, PropertyMock, patch

from charms.pgbouncer_k8s.v0.pgb import parse_dict_to_kv_string
from ops.model import Unit
from ops.testing import Harness

from charm import PgBouncerK8sCharm
Expand Down Expand Up @@ -279,3 +280,21 @@ def test_on_relation_broken(

_delete_user.assert_called_once_with(username)
_set_rel_dbs.assert_called_once_with({})

def test_get_allowed_subnets(self):
rel = self.charm.model.get_relation("db", self.db_rel_id)
for key in rel.data.keys():
if isinstance(key, Unit):
rel.data[key]["egress-subnets"] = "10.0.0.10,10.0.0.11"

assert "10.0.0.10,10.0.0.11" == self.charm.legacy_db_relation.get_allowed_subnets(rel)

def test_get_allowed_units(self):
rel = self.charm.model.get_relation("db", self.db_rel_id)

assert "client_app/0" == self.charm.legacy_db_relation.get_allowed_units(rel)

def test_get_external_app(self):
rel = self.charm.model.get_relation("db", self.db_rel_id)

assert "client_app" == self.charm.legacy_db_relation.get_external_app(rel).name
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ commands =
poetry run coverage run --source={[vars]src_path},{[vars]lib_path} \
-m pytest -v --tb native -s {posargs} {[vars]tests_path}/unit
poetry run coverage report
poetry run coverage xml

[testenv:integration]
description = Run integration tests
Expand Down

0 comments on commit e03c8ce

Please sign in to comment.