@@ -3,6 +3,7 @@ package stackitprovider
33import (
44 "context"
55 "encoding/json"
6+ "fmt"
67 "net/http"
78 "net/http/httptest"
89 "testing"
@@ -143,6 +144,61 @@ func TestNoRRSetFound(t *testing.T) {
143144 assert .Error (t , err )
144145}
145146
147+ func TestPartialUpdate (t * testing.T ) {
148+ t .Parallel ()
149+
150+ ctx := context .Background ()
151+ validZoneResponse := getValidResponseZoneAllBytes (t )
152+
153+ mux := http .NewServeMux ()
154+ server := httptest .NewServer (mux )
155+ defer server .Close ()
156+
157+ // Set up common endpoint for all types of changes
158+ setUpCommonEndpoints (mux , validZoneResponse , http .StatusOK )
159+ // Set up change type-specific endpoints
160+ // based on setUpChangeTypeEndpoints(t, mux, validRRSetResponse, http.StatusOK, Update)
161+ // but extended to check that the rrset is updated
162+ rrSetUpdated := false
163+ mux .HandleFunc (
164+ "/v1/projects/1234/zones/1234/rrsets/1234" ,
165+ func (w http.ResponseWriter , r * http.Request ) {
166+ w .Header ().Set ("Content-Type" , "application/json" )
167+ w .WriteHeader (http .StatusOK )
168+ fmt .Println (r .Method )
169+ if r .Method == http .MethodPatch {
170+ rrSetUpdated = true
171+ }
172+ },
173+ )
174+ mux .HandleFunc (
175+ "/v1/projects/1234/zones/1234/rrsets" ,
176+ func (w http.ResponseWriter , r * http.Request ) {
177+ getRrsetsResponseRecordsNonPaged (t , w , "1234" )
178+ },
179+ )
180+ mux .HandleFunc (
181+ "/v1/projects/1234/zones/5678/rrsets" ,
182+ func (w http.ResponseWriter , r * http.Request ) {
183+ getRrsetsResponseRecordsNonPaged (t , w , "5678" )
184+ },
185+ )
186+
187+ stackitDnsProvider , err := getDefaultTestProvider (server )
188+ assert .NoError (t , err )
189+
190+ // Create update change
191+ changes := getChangeTypeChanges (Update )
192+ // Add task to create invalid endpoint
193+ changes .Create = []* endpoint.Endpoint {
194+ {DNSName : "notfound.com" , Targets : endpoint.Targets {"test.notfound.com" }},
195+ }
196+
197+ err = stackitDnsProvider .ApplyChanges (ctx , changes )
198+ assert .Error (t , err )
199+ assert .True (t , rrSetUpdated , "rrset was not updated" )
200+ }
201+
146202// setUpCommonEndpoints for all change types.
147203func setUpCommonEndpoints (mux * http.ServeMux , responseZone []byte , responseZoneCode int ) {
148204 mux .HandleFunc ("/v1/projects/1234/zones" , func (w http.ResponseWriter , r * http.Request ) {
0 commit comments