Skip to content

Commit

Permalink
Merge pull request #3596 from WowVeryLogin/denis/FLPROD-796
Browse files Browse the repository at this point in the history
FLPROD-796: Fixing wrong response type for snippet update endpoint
  • Loading branch information
jacobbednarz authored Nov 12, 2024
2 parents 72fcc88 + d6feff7 commit 6e537fe
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 24 deletions.
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

0 comments on commit 6e537fe

Please sign in to comment.