Repository: cloudflare/cloudflare-go
Pull request #1172 (2023-01-09 17:11:02)

WDAPI-1221 Fix Update Method to be PUT from PATCH
Provide a general summary of your changes in the title above. You should
remove this overview, any sections and any section descriptions you
don't need below before submitting. There isn't a strict requirement to
use this template if you can structure your description and still cover
these points.

## Description
Bug fix change update method from PATCH To PUT which API expects
## Has your change been tested?

Yes Locally using terraform-provider as well.

## Screenshots (if appropriate):

## Types of changes

What sort of change does your code introduce/modify?

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Checklist:

- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
- [x] This change is using publicly documented (api.cloudflare.com or developers.cloudflare.com) and stable APIs.

[1]: https://help.github.com/articles/closing-issues-using-keywords/



Patch:
diff --git a/.changelog/1172.txt b/.changelog/1172.txt
new file mode 100644
index 000000000..9b4a5bff2
--- /dev/null
+++ b/.changelog/1172.txt
@@ -0,0 +1,3 @@
+```release-note:bug
+managednetworks: Update should be PUT
+```
diff --git a/devices_managed_networks.go b/devices_managed_networks.go
index 1f6129a6a..2e308eb21 100644
--- a/devices_managed_networks.go
+++ b/devices_managed_networks.go
@@ -103,7 +103,7 @@ func (api *API) UpdateDeviceManagedNetwork(ctx context.Context, rc *ResourceCont
 
 	uri := fmt.Sprintf("/%s/%s/devices/networks/%s", rc.Level, rc.Identifier, params.NetworkID)
 
-	res, err := api.makeRequestContext(ctx, http.MethodPatch, uri, params)
+	res, err := api.makeRequestContext(ctx, http.MethodPut, uri, params)
 	if err != nil {
 		return DeviceManagedNetwork{}, err
 	}


Test patch:
diff --git a/devices_managed_networks_test.go b/devices_managed_networks_test.go
index 7f2f4bb6b..c62c7c679 100644
--- a/devices_managed_networks_test.go
+++ b/devices_managed_networks_test.go
@@ -149,6 +149,57 @@ func TestCreateDeviceManagedNetwork(t *testing.T) {
 	}
 }
 
+func TestUpdateDeviceManagedNetwork(t *testing.T) {
+	setup()
+	defer teardown()
+
+	handler := func(w http.ResponseWriter, r *http.Request) {
+		assert.Equal(t, http.MethodPut, r.Method, "Expected method 'PUT', got %s", r.Method)
+		w.Header().Set("content-type", "application/json")
+		fmt.Fprintf(w, `{
+			"success": true,
+			"errors": [],
+			"messages": [],
+			"result":
+			  {
+				"network_id": "%s",
+				"type": "tls",
+				"name": "managed-network-1",
+				"config": {
+				  "tls_sockaddr": "foobar:1234",
+				  "sha256": "b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c"
+				}
+			  }
+		  }`, testNetworkID)
+	}
+
+	want := DeviceManagedNetwork{
+		NetworkID: testNetworkID,
+		Type:      "tls",
+		Name:      "managed-network-1",
+		Config: &Config{
+			TlsSockAddr: "foobar:1234",
+			Sha256:      "b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c",
+		},
+	}
+
+	mux.HandleFunc("/accounts/"+testAccountID+"/devices/networks/"+testNetworkID, handler)
+
+	actual, err := client.UpdateDeviceManagedNetwork(context.Background(), AccountIdentifier(testAccountID), UpdateDeviceManagedNetworkParams{
+		NetworkID: testNetworkID,
+		Type:      "tls",
+		Name:      "managed-network-1",
+		Config: &Config{
+			TlsSockAddr: "foobar:1234",
+			Sha256:      "b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c",
+		},
+	})
+
+	if assert.NoError(t, err) {
+		assert.Equal(t, want, actual)
+	}
+}
+
 func TestDeleteDeviceManagedNetwork(t *testing.T) {
 	setup()
 	defer teardown()