Skip to content

Commit 08f2da1

Browse files
committed
Test schema, add min length to strings
1 parent 456fe2f commit 08f2da1

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

aws_project_costs/project-cost-schema.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"$schema": "http://json-schema.org/draft/2020-12/schema",
3-
"$id": "https://github.com/hic-infra/TODO",
3+
"$id": "https://github.com/hic-infra/hic-aws-project-cost",
44
"title": "AWS project cost configuration",
55
"type": "object",
66
"properties": {
77
"proj-tag-names": {
88
"description": "A mapping of AWS project tags to the canonical project name",
99
"type": "object",
1010
"additionalProperties": {
11-
"type": "string"
11+
"type": "string",
12+
"minLength": 1
1213
}
1314
},
1415
"project-groups": {
@@ -17,7 +18,8 @@
1718
"additionalProperties": {
1819
"type": "array",
1920
"items": {
20-
"type": "string"
21+
"type": "string",
22+
"minLength": 1
2123
}
2224
}
2325
},
@@ -29,7 +31,8 @@
2931
"properties": {
3032
"name": {
3133
"description": "Name of the AWS account",
32-
"type": "string"
34+
"type": "string",
35+
"minLength": 1
3336
},
3437
"billing-type": {
3538
"description": "Whether costs should be split across multiple projects or assigned to a single project",
@@ -45,12 +48,14 @@
4548
"type": "array",
4649
"minItems": 1,
4750
"items": {
48-
"type": "string"
51+
"type": "string",
52+
"minLength": 1
4953
}
5054
},
5155
"project": {
5256
"description": "The project responsible for all costs, required for billing-type=project-specific",
53-
"type": "string"
57+
"type": "string",
58+
"minLength": 1
5459
}
5560
},
5661
"required": ["name", "billing-type"],

tests/test_project_costs.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@
44
import yaml
55

66
from aws_project_costs.project_costs import analyse_costs_csv
7-
8-
# from aws_project_costs.schema import validate
7+
from aws_project_costs.schema import validate
98

109
EXAMPLE_DIR = Path(__file__).parent / ".." / "example"
1110

1211

12+
def test_schema_validate():
13+
config_yaml = EXAMPLE_DIR / "projects.yaml"
14+
with (config_yaml).open() as f:
15+
cfg = yaml.safe_load(f)
16+
errors = validate(cfg, raise_on_error=False)
17+
assert len(errors) == 0
18+
19+
1320
def test_analyse_costs_csv(tmp_path):
1421
config_yaml = EXAMPLE_DIR / "projects.yaml"
1522
input_csv = EXAMPLE_DIR / "2024-01-01_2024-02-01.csv"

0 commit comments

Comments
 (0)