Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FLPROD-796: Fixing wrong response type for snippet update endpoint #3596

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3596.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
snippets: fix response type for `UpdateZoneSnippet`
```
4 changes: 2 additions & 2 deletions snippets.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func snippetMultipartBody(request SnippetRequest) (string, *bytes.Buffer, error)
return mw.Boundary(), body, nil
}

func (api *API) UpdateZoneSnippet(ctx context.Context, rc *ResourceContainer, params SnippetRequest) ([]Snippet, error) {
func (api *API) UpdateZoneSnippet(ctx context.Context, rc *ResourceContainer, params SnippetRequest) (*Snippet, error) {
if rc.Identifier == "" {
return nil, ErrMissingZoneID
}
Expand All @@ -153,7 +153,7 @@ func (api *API) UpdateZoneSnippet(ctx context.Context, rc *ResourceContainer, pa
return nil, err
}

result := SnippetsResponse{}
result := SnippetResponse{}
if err := json.Unmarshal(res, &result); err != nil {
return nil, fmt.Errorf("%s: %w", errUnmarshalError, err)
}
Expand Down
4 changes: 2 additions & 2 deletions snippets_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (api *API) ListZoneSnippetsRules(ctx context.Context, rc *ResourceContainer
return nil, ErrMissingZoneID
}

uri := buildURI(fmt.Sprintf("/zones/%s/snippets/rules", rc.Identifier), nil)
uri := buildURI(fmt.Sprintf("/zones/%s/snippets/snippet_rules", rc.Identifier), nil)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return nil, err
Expand All @@ -45,7 +45,7 @@ func (api *API) UpdateZoneSnippetsRules(ctx context.Context, rc *ResourceContain
return nil, ErrMissingZoneID
}

uri := fmt.Sprintf("/zones/%s/snippets/rules", rc.Identifier)
uri := fmt.Sprintf("/zones/%s/snippets/snippet_rules", rc.Identifier)

payload, err := json.Marshal(params)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions snippets_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestSnippetsRules(t *testing.T) {
"messages": []
}`)
}
mux.HandleFunc("/zones/"+testZoneID+"/snippets/rules", handler)
mux.HandleFunc("/zones/"+testZoneID+"/snippets/snippet_rules", handler)

want := []SnippetRule{
{
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestUpdateSnippetsRules(t *testing.T) {
}`)
}

mux.HandleFunc("/zones/"+testZoneID+"/snippets/rules", handler)
mux.HandleFunc("/zones/"+testZoneID+"/snippets/snippet_rules", handler)
toUpdate := []SnippetRule{
{
Expression: "true",
Expand Down
23 changes: 5 additions & 18 deletions snippets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,12 @@ func TestUpdateSnippets(t *testing.T) {
assert.Equal(t, http.MethodPut, r.Method, "Expected method 'PUT', got %s", r.Method)
w.Header().Set("content-type", "application/json")
fmt.Fprint(w, `{
"result": [
"result":
{
"snippet_name": "some_id_1",
"created_on":"0001-01-01T00:00:00Z",
"modified_on":"0001-01-01T00:00:00Z"
},
{
"snippet_name": "some_id_2",
"created_on":"0001-01-01T00:00:00Z",
"modified_on":"0001-01-01T00:00:00Z"
}
],
"success": true,
"errors": [],
"messages": []
Expand All @@ -149,17 +143,10 @@ func TestUpdateSnippets(t *testing.T) {
},
},
}
want := []Snippet{
{
SnippetName: "some_id_1",
CreatedOn: &time.Time{},
ModifiedOn: &time.Time{},
},
{
SnippetName: "some_id_2",
CreatedOn: &time.Time{},
ModifiedOn: &time.Time{},
},
want := &Snippet{
SnippetName: "some_id_1",
CreatedOn: &time.Time{},
ModifiedOn: &time.Time{},
}
zoneActual, err := client.UpdateZoneSnippet(context.Background(), ZoneIdentifier(testZoneID), toUpdate)
if assert.NoError(t, err) {
Expand Down
Loading