Skip to content

Commit 5dc9791

Browse files
[DPE-8276] Add unit tests (#2)
* Add unit tests Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Minor updates on dependencies and tox environments Signed-off-by: Marcelo Henrique Neppel <[email protected]> * Update authors to Canonical Data Platform Signed-off-by: Marcelo Henrique Neppel <[email protected]> --------- Signed-off-by: Marcelo Henrique Neppel <[email protected]>
1 parent 15ca38c commit 5dc9791

File tree

9 files changed

+1168
-0
lines changed

9 files changed

+1168
-0
lines changed

pyproject.toml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Copyright 2025 Canonical Ltd.
2+
# See LICENSE file for licensing details.
3+
4+
[project]
5+
name = "postgresql-charms-single-kernel"
6+
dynamic = ["version"]
7+
description = "Shared and reusable code for PostgreSQL-related charms"
8+
readme = "README.md"
9+
license = "Apache-2.0"
10+
authors = [
11+
{name = "Canonical Data Platform", email = "[email protected]"}
12+
]
13+
classifiers = [
14+
"Development Status :: 3 - Alpha",
15+
"Intended Audience :: Developers",
16+
"Operating System :: POSIX :: Linux",
17+
]
18+
requires-python = ">=3.8,<4.0"
19+
20+
[dependency-groups]
21+
lib = [
22+
"ops>=2.0.0",
23+
"psycopg2>=2.9.10",
24+
]
25+
format = [
26+
"ruff==0.12.11"
27+
]
28+
lint = [
29+
"codespell==2.4.1"
30+
]
31+
unit = [
32+
"coverage[toml]==7.9.1; python_version > '3.8'",
33+
"pytest>=8.3.5; python_version < '3.9'",
34+
"pytest==8.4.1; python_version >= '3.9'"
35+
]
36+
37+
# Testing tools configuration
38+
[tool.coverage.run]
39+
branch = true
40+
41+
[tool.coverage.report]
42+
show_missing = true
43+
exclude_lines = [
44+
"logger\\.debug"
45+
]
46+
47+
[tool.pytest.ini_options]
48+
minversion = "6.0"
49+
log_cli_level = "INFO"
50+
51+
# Linting tools configuration
52+
[tool.ruff]
53+
# preview and explicit preview are enabled for CPY001
54+
preview = true
55+
target-version = "py38"
56+
src = ["src", "."]
57+
line-length = 99
58+
59+
[tool.ruff.lint]
60+
explicit-preview-rules = true
61+
select = ["A", "E", "W", "F", "C", "N", "D", "I001", "B", "CPY001", "RUF", "S", "SIM", "UP", "TCH"]
62+
extend-ignore = [
63+
"D203",
64+
"D204",
65+
"D213",
66+
"D215",
67+
"D400",
68+
"D404",
69+
"D406",
70+
"D407",
71+
"D408",
72+
"D409",
73+
"D413",
74+
]
75+
# Ignore E501 because using black creates errors with this
76+
# Ignore D107 Missing docstring in __init__
77+
ignore = ["E501", "D107"]
78+
79+
[tool.ruff.lint.per-file-ignores]
80+
"tests/*" = [
81+
"D100", "D101", "D102", "D103", "D104",
82+
# Asserts
83+
"B011",
84+
# Disable security checks for tests
85+
"S",
86+
]
87+
88+
[tool.ruff.lint.flake8-copyright]
89+
# Check for properly formatted copyright header in each file
90+
author = "Canonical Ltd."
91+
notice-rgx = "Copyright\\s\\d{4}([-,]\\d{4})*\\s+"
92+
min-file-size = 1
93+
94+
[tool.ruff.lint.mccabe]
95+
max-complexity = 10
96+
97+
[tool.ruff.lint.pydocstyle]
98+
convention = "google"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Copyright 2025 Canonical Ltd.
2+
# See LICENSE file for licensing details.
3+
"""PostgreSQL Operators Single Kernel."""
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2025 Canonical Ltd.
2+
# See LICENSE file for licensing details.
3+
"""Skeleton for the abstract charm."""
4+
5+
from ops.charm import CharmBase
6+
7+
from .config.literals import SYSTEM_USERS, USER
8+
from .utils.postgresql import PostgreSQL
9+
10+
11+
class AbstractPostgreSQLCharm(CharmBase):
12+
"""An abstract PostgreSQL charm."""
13+
14+
def __init__(self, *args):
15+
super().__init__(*args)
16+
17+
self.postgresql = PostgreSQL(
18+
primary_host="localhost",
19+
current_host="localhost",
20+
user=USER,
21+
# The password is hardcoded because this is an abstract charm and
22+
# it meant to be used only in unit tests.
23+
password="test-password", # noqa S106
24+
database="test-database",
25+
system_users=SYSTEM_USERS,
26+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2025 Canonical Ltd.
2+
# See LICENSE file for licensing details.
3+
#
4+
# This file is here only to run unit tests.
5+
type: charm
6+
name: postgresql-single-kernel
7+
title: PostgreSQL Single Kernel Charm
8+
summary: Placeholder charm for unit tests.
9+
description: Placeholder charm for unit tests.
10+
11+
12+
platforms:
13+
amd64:
14+
arm64:
15+
16+
peers:
17+
database-peers:
18+
interface: postgresql_peers
19+
20+
provides:
21+
database:
22+
interface: postgresql_client

single_kernel_postgresql/config/literals.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
This module should contain the literals used in the charms (paths, enums, etc).
66
"""
77

8+
# Relations.
9+
PEER = "database-peers"
10+
811
# Users.
912
BACKUP_USER = "backup"
1013
MONITORING_USER = "monitoring"

0 commit comments

Comments
 (0)