Skip to content

Commit 04e471e

Browse files
committed
PDOK-18065 Atom-Operator - validation unit-tests
1 parent dcafc04 commit 04e471e

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

internal/webhook/v3/atom_webhook_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ var _ = Describe("Atom Webhook", func() {
7171
Expect(errors).To(BeNil())
7272
Expect(len(warnings)).To(Equal(0))
7373
})
74+
7475
It("Should deny creation if no labels are available", func() {
7576
By("simulating an invalid creation scenario")
7677
input, err := os.ReadFile("test_data/input/2-create-error-no-lables.yaml")
@@ -106,6 +107,29 @@ var _ = Describe("Atom Webhook", func() {
106107
Expect(errors).To(BeNil())
107108
Expect(len(warnings)).To(Equal(0))
108109
})
109-
})
110110

111+
It("Should deny update atom with error label names are immutable", func() {
112+
By("simulating a valid creation scenario")
113+
input, err := os.ReadFile("test_data/input/1-create-no-error-no-warning.yaml")
114+
Expect(err).NotTo(HaveOccurred())
115+
atomOld := &pdoknlv3.Atom{}
116+
err = yaml.Unmarshal(input, atomOld)
117+
Expect(err).NotTo(HaveOccurred())
118+
warnings, errors := validator.ValidateCreate(ctx, atomOld)
119+
Expect(errors).To(BeNil())
120+
Expect(len(warnings)).To(Equal(0))
121+
122+
By("simulating a valid update scenario")
123+
input, err = os.ReadFile("test_data/input/4-update-error-labels-immutable.yaml")
124+
Expect(err).NotTo(HaveOccurred())
125+
atomNew := &pdoknlv3.Atom{}
126+
err = yaml.Unmarshal(input, atomNew)
127+
Expect(err).NotTo(HaveOccurred())
128+
warnings, errors = validator.ValidateUpdate(ctx, atomOld, atomNew)
129+
130+
expectedError := fmt.Errorf("Atom.pdok.nl \"asis-readonly-prod\" is invalid: [metadata.labels.pdok.nl/dataset-id: Required value: labels cannot be removed, metadata.labels.pdok.nl/dataset-idsssssssss: Forbidden: new labels cannot be added]")
131+
Expect(len(warnings)).To(Equal(0))
132+
Expect(expectedError.Error()).To(Equal(errors.Error()))
133+
})
134+
})
111135
})
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
apiVersion: pdok.nl/v3
2+
kind: Atom
3+
metadata:
4+
annotations:
5+
kangaroo.pdok.nl/lifecycle-phase: prod
6+
kangaroo.pdok.nl/service-bundle-ids: 65daed5f-e9e4-5791-a7c9-7e9effcca520
7+
kangaroo.pdok.nl/readonly: "true"
8+
labels:
9+
pdok.nl/dataset-idsssssssss: wetlands
10+
pdok.nl/owner-id: rvo
11+
pdok.nl/service-type: atom
12+
name: asis-readonly-prod
13+
namespace: services
14+
spec:
15+
service:
16+
baseUrl: http://localhost:32788/rvo/wetlands/atom
17+
datasetFeeds:
18+
- author:
19+
20+
name: Ministerie van EL&I - GIS Competence Center
21+
datasetMetadataLinks:
22+
metadataIdentifier: 07d73b60-dfd6-4c54-9c82-9fac70c6c48e
23+
templates:
24+
- csw
25+
- html
26+
entries:
27+
- content:
28+
Wetlands zijn de natte natuurgebieden in Nederland (44 gebieden).
29+
Het Wetland verdrag is op 2 februari 1971 te Ramsar in Iran ondertekend.
30+
Nederland was een van de zestien landen die het Verdrag toen ondertekende.
31+
downloadlinks:
32+
- data: public/rvo/wetlands/65daed5f-e9e4-5791-a7c9-7e9effcca520/3/wetlands.gpkg
33+
polygon:
34+
bbox:
35+
maxx: "7.5553527"
36+
maxy: "55.66948"
37+
minx: "2.354173"
38+
miny: "50.71447"
39+
srs:
40+
name: Amersfoort / RD New
41+
uri: https://www.opengis.net/def/crs/EPSG/0/28992
42+
technicalName: wetlands
43+
title: wetlands
44+
updated: "2025-02-28T09:04:17Z"
45+
spatialDatasetIdentifierCode: 07d73b60-dfd6-4c54-9c82-9fac70c6c48e
46+
spatialDatasetIdentifierNamespace: http://www.pdok.nl
47+
subtitle: wetlands
48+
technicalName: wetlands
49+
title: wetlands
50+
lang: nl
51+
ownerInfoRef: pdok
52+
rights: https://creativecommons.org/publicdomain/zero/1.0/deed.nl
53+
serviceMetadataLinks:
54+
metadataIdentifier: 2751ba40-5100-4186-81be-b7fdee95b49c
55+
templates:
56+
- csw
57+
- opensearch
58+
- html
59+
subtitle: Download Service van wetlands new title
60+
title: Wetlands new title

0 commit comments

Comments
 (0)