Skip to content

Commit

Permalink
Unit test for HTTP request headers
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas11 committed Sep 3, 2024
1 parent 1d65b14 commit 2bb2d94
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion provider/pkg/azure/client_azcore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestNormalizeLocationHeader(t *testing.T) {
})
}

func TestInitRequestQueryParamsHandling(t *testing.T) {
func TestInitRequestQueryParams(t *testing.T) {
c, err := NewAzCoreClient(&fake.TokenCredential{}, "pulumi", cloud.AzurePublic, nil)
require.NoError(t, err)
client := c.(*azCoreClient)
Expand All @@ -82,6 +82,30 @@ func TestInitRequestQueryParamsHandling(t *testing.T) {
assert.Equal(t, []string{"a", "b"}, query["slice"])
}

func TestInitRequestHeaders(t *testing.T) {
c, err := NewAzCoreClient(&fake.TokenCredential{}, "pulumi-agent", cloud.AzurePublic, nil)
require.NoError(t, err)
client := c.(*azCoreClient)

queryParams := map[string]any{"api-version": "2022-09-01"}

for method, contentType := range map[string]string{
http.MethodGet: "",
http.MethodDelete: "",
http.MethodPost: "application/json; charset=utf-8",
http.MethodPut: "application/json; charset=utf-8",
http.MethodPatch: "application/json; charset=utf-8",
} {
req, err := client.initRequest(context.Background(), method, "/subscriptions/123", queryParams)
require.NoError(t, err)

headers := req.Raw().Header
assert.Equal(t, "pulumi-agent", headers.Get("User-Agent"))
assert.Equal(t, "application/json", headers.Get("Accept"))
assert.Equal(t, contentType, headers.Get("Content-Type"))
}
}

func TestRequestQueryParams(t *testing.T) {
const resourceId = "/subscriptions/123/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/vm"

Expand Down

0 comments on commit 2bb2d94

Please sign in to comment.