@@ -40,12 +40,12 @@ func TestApplyChanges(t *testing.T) {
40
40
func testApplyChanges (t * testing.T , changeType ChangeType ) {
41
41
t .Helper ()
42
42
ctx := context .Background ()
43
- validRespJson := getValidResponseZoneALlBytes (t )
43
+ validZoneResponse := getValidResponseZoneALlBytes (t )
44
44
validRRSetResponse := getValidResponseRRSetAllBytes (t )
45
- invalidRespJson := []byte (`{"invalid: "json"` )
45
+ invalidZoneResponse := []byte (`{"invalid: "json"` )
46
46
47
47
// Test cases
48
- tests := getApplyChangesBasicTestCases (validRespJson , validRRSetResponse , invalidRespJson )
48
+ tests := getApplyChangesBasicTestCases (validZoneResponse , validRRSetResponse , invalidZoneResponse )
49
49
50
50
for _ , tt := range tests {
51
51
tt := tt
@@ -79,6 +79,69 @@ func testApplyChanges(t *testing.T, changeType ChangeType) {
79
79
}
80
80
}
81
81
82
+ func TestNoMatchingZoneFound (t * testing.T ) {
83
+ t .Parallel ()
84
+
85
+ ctx := context .Background ()
86
+ validZoneResponse := getValidResponseZoneALlBytes (t )
87
+
88
+ mux := http .NewServeMux ()
89
+ server := httptest .NewServer (mux )
90
+ defer server .Close ()
91
+
92
+ // Set up common endpoint for all types of changes
93
+ setUpCommonEndpoints (mux , validZoneResponse , http .StatusOK )
94
+
95
+ stackitDnsProvider , err := getDefaultTestProvider (server )
96
+ assert .NoError (t , err )
97
+
98
+ changes := & plan.Changes {
99
+ Create : []* endpoint.Endpoint {
100
+ {DNSName : "notfound.com" , Targets : endpoint.Targets {"test.notfound.com" }},
101
+ },
102
+ UpdateNew : []* endpoint.Endpoint {},
103
+ Delete : []* endpoint.Endpoint {},
104
+ }
105
+
106
+ err = stackitDnsProvider .ApplyChanges (ctx , changes )
107
+ assert .Error (t , err )
108
+ }
109
+
110
+ func TestNoRRSetFound (t * testing.T ) {
111
+ t .Parallel ()
112
+
113
+ ctx := context .Background ()
114
+ validZoneResponse := getValidResponseZoneALlBytes (t )
115
+ rrSets := getValidResponseRRSetAll ()
116
+ rrSets .RrSets [0 ].Name = "notfound.test.com"
117
+ validRRSetResponse , err := json .Marshal (rrSets )
118
+ assert .NoError (t , err )
119
+
120
+ mux := http .NewServeMux ()
121
+ server := httptest .NewServer (mux )
122
+ defer server .Close ()
123
+
124
+ // Set up common endpoint for all types of changes
125
+ setUpCommonEndpoints (mux , validZoneResponse , http .StatusOK )
126
+
127
+ mux .HandleFunc (
128
+ "/v1/projects/1234/zones/1234/rrsets" ,
129
+ responseHandler (validRRSetResponse , http .StatusOK ),
130
+ )
131
+
132
+ stackitDnsProvider , err := getDefaultTestProvider (server )
133
+ assert .NoError (t , err )
134
+
135
+ changes := & plan.Changes {
136
+ UpdateNew : []* endpoint.Endpoint {
137
+ {DNSName : "test.com" , Targets : endpoint.Targets {"notfound.test.com" }},
138
+ },
139
+ }
140
+
141
+ err = stackitDnsProvider .ApplyChanges (ctx , changes )
142
+ assert .Error (t , err )
143
+ }
144
+
82
145
// setUpCommonEndpoints for all change types.
83
146
func setUpCommonEndpoints (mux * http.ServeMux , responseZone []byte , responseZoneCode int ) {
84
147
mux .HandleFunc ("/v1/projects/1234/zones" , func (w http.ResponseWriter , r * http.Request ) {
@@ -153,9 +216,9 @@ func getChangeTypeChanges(changeType ChangeType) *plan.Changes {
153
216
}
154
217
155
218
func getApplyChangesBasicTestCases ( //nolint:funlen // Test cases are long
156
- validRespJson []byte ,
219
+ validZoneResponse []byte ,
157
220
validRRSetResponse []byte ,
158
- invalidRespJson []byte ,
221
+ invalidZoneResponse []byte ,
159
222
) []struct {
160
223
name string
161
224
responseZone []byte
@@ -176,7 +239,7 @@ func getApplyChangesBasicTestCases( //nolint:funlen // Test cases are long
176
239
}{
177
240
{
178
241
"Valid response" ,
179
- validRespJson ,
242
+ validZoneResponse ,
180
243
http .StatusOK ,
181
244
validRRSetResponse ,
182
245
http .StatusAccepted ,
@@ -203,7 +266,7 @@ func getApplyChangesBasicTestCases( //nolint:funlen // Test cases are long
203
266
},
204
267
{
205
268
"Zone response Invalid JSON" ,
206
- invalidRespJson ,
269
+ invalidZoneResponse ,
207
270
http .StatusOK ,
208
271
validRRSetResponse ,
209
272
http .StatusAccepted ,
@@ -212,7 +275,7 @@ func getApplyChangesBasicTestCases( //nolint:funlen // Test cases are long
212
275
},
213
276
{
214
277
"Zone response, Rrset response 403" ,
215
- validRespJson ,
278
+ validZoneResponse ,
216
279
http .StatusOK ,
217
280
nil ,
218
281
http .StatusForbidden ,
@@ -221,7 +284,7 @@ func getApplyChangesBasicTestCases( //nolint:funlen // Test cases are long
221
284
},
222
285
{
223
286
"Zone response, Rrset response 500" ,
224
- validRespJson ,
287
+ validZoneResponse ,
225
288
http .StatusOK ,
226
289
nil ,
227
290
http .StatusInternalServerError ,
@@ -231,9 +294,9 @@ func getApplyChangesBasicTestCases( //nolint:funlen // Test cases are long
231
294
// swagger client does not return an error when the response is invalid json
232
295
{
233
296
"Zone response, Rrset response Invalid JSON" ,
234
- validRespJson ,
297
+ validZoneResponse ,
235
298
http .StatusOK ,
236
- invalidRespJson ,
299
+ invalidZoneResponse ,
237
300
http .StatusAccepted ,
238
301
false ,
239
302
http .MethodPost ,
@@ -257,10 +320,10 @@ func getValidResponseZoneALlBytes(t *testing.T) []byte {
257
320
t .Helper ()
258
321
259
322
zones := getValidZoneResponseAll ()
260
- validRespJson , err := json .Marshal (zones )
323
+ validZoneResponse , err := json .Marshal (zones )
261
324
assert .NoError (t , err )
262
325
263
- return validRespJson
326
+ return validZoneResponse
264
327
}
265
328
266
329
func getValidZoneResponseAll () stackitdnsclient.ZoneResponseZoneAll {
0 commit comments