Skip to content

Commit

Permalink
Fix empty $expand value in GetResourceWithExpandAPIVersionQuery()
Browse files Browse the repository at this point in the history
Signed-off-by: Zhecheng Li <zhechengli@microsoft.com>
  • Loading branch information
lzhecheng committed Jun 20, 2022
1 parent 7101820 commit 6ed079c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/azureclients/armclient/azure_armclient.go
Expand Up @@ -348,11 +348,13 @@ func (c *Client) GetResourceWithExpandAPIVersionQuery(ctx context.Context, resou
autorest.AsGet(),
autorest.WithBaseURL(c.baseURI),
autorest.WithPathParameters("{resourceID}", map[string]interface{}{"resourceID": resourceID}),
autorest.WithQueryParameters(map[string]interface{}{
"$expand": autorest.Encode("query", expand),
}),
withAPIVersion(apiVersion),
}
if expand != "" {
decorators = append(decorators, autorest.WithQueryParameters(map[string]interface{}{
"$expand": autorest.Encode("query", expand),
}))
}

preparer := autorest.CreatePreparer(decorators...)
request, err := preparer.Prepare((&http.Request{}).WithContext(ctx))
Expand Down
9 changes: 9 additions & 0 deletions pkg/azureclients/armclient/azure_armclient_test.go
Expand Up @@ -306,6 +306,15 @@ func TestGetResource(t *testing.T) {
return armClient.GetResourceWithExpandAPIVersionQuery(ctx, testResourceID, "data", apiVersion)
},
},
{
description: "GetResourceWithExpandAPIVersionQuery-empty-expand",
expectedURIResource: "/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Network/publicIPAddresses/testPIP?api-version=2019-01-01",
apiVersion: "2018-01-01",
expectedAPIVersion: "2019-01-01",
getResource: func(ctx context.Context, armClient *Client, apiVersion string, params map[string]interface{}) (*http.Response, *retry.Error) {
return armClient.GetResourceWithExpandAPIVersionQuery(ctx, testResourceID, "", apiVersion)
},
},
}

for _, tc := range testcases {
Expand Down

0 comments on commit 6ed079c

Please sign in to comment.