Skip to content

Commit 1a9f56a

Browse files
committed
PDOK-18065 Atom-Operator - validation unit-tests
1 parent dfc2635 commit 1a9f56a

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
@@ -143,7 +143,7 @@ var _ = Describe("Atom Webhook", func() {
143143
Expect(errors).To(BeNil())
144144
Expect(len(warnings)).To(Equal(0))
145145

146-
By("simulating a valid update scenario")
146+
By("simulating an invalid update scenario. Lablels are immutable")
147147
input, err = os.ReadFile("test_data/input/5-update-error-labels-immutable.yaml")
148148
Expect(err).NotTo(HaveOccurred())
149149
atomNew := &pdoknlv3.Atom{}
@@ -155,5 +155,29 @@ var _ = Describe("Atom Webhook", func() {
155155
Expect(len(warnings)).To(Equal(0))
156156
Expect(expectedError.Error()).To(Equal(errors.Error()))
157157
})
158+
159+
It("Should deny update atom with error URL are immutable", func() {
160+
By("simulating a valid creation scenario")
161+
input, err := os.ReadFile("test_data/input/1-create-no-error-no-warning.yaml")
162+
Expect(err).NotTo(HaveOccurred())
163+
atomOld := &pdoknlv3.Atom{}
164+
err = yaml.Unmarshal(input, atomOld)
165+
Expect(err).NotTo(HaveOccurred())
166+
warnings, errors := validator.ValidateCreate(ctx, atomOld)
167+
Expect(errors).To(BeNil())
168+
Expect(len(warnings)).To(Equal(0))
169+
170+
By("simulating an invalid update scenario. URL is immutable")
171+
input, err = os.ReadFile("test_data/input/6-update-error-url-immutable.yaml")
172+
Expect(err).NotTo(HaveOccurred())
173+
atomNew := &pdoknlv3.Atom{}
174+
err = yaml.Unmarshal(input, atomNew)
175+
Expect(err).NotTo(HaveOccurred())
176+
warnings, errors = validator.ValidateUpdate(ctx, atomOld, atomNew)
177+
178+
expectedError := fmt.Errorf("Atom.pdok.nl \"asis-readonly-prod\" is invalid: spec.service.baseUrl: Forbidden: is immutable")
179+
Expect(len(warnings)).To(Equal(0))
180+
Expect(expectedError.Error()).To(Equal(errors.Error()))
181+
})
158182
})
159183
})
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-id: 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/rvo44444/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
60+
title: Wetlands

0 commit comments

Comments
 (0)