Skip to content
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# UNRELEASED
# v1.67.1

## Bug Fixes

* Fixes a bug in `NewRequest` that did not allow query parameters to be specified in the first parameter, which broke several methods: `RegistryModules ReadVersion`, `VariableSets UpdateWorkspaces`, and `Workspaces Readme` by @brandonc [#982](https://github.com/hashicorp/go-tfe/pull/982)

# v1.67.0

Expand Down
5 changes: 5 additions & 0 deletions tfe.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ func (c *Client) NewRequestWithAdditionalQueryParams(method, path string, reqBod
}
}

// Will contain combined query values from path parsing and
// additionalQueryParams parameter
q := make(url.Values)

// Create a request specific headers map.
Expand Down Expand Up @@ -310,6 +312,9 @@ func (c *Client) NewRequestWithAdditionalQueryParams(method, path string, reqBod
body = reqBody
}

for k, v := range u.Query() {
q[k] = v
}
Comment on lines +315 to +317
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

for k, v := range additionalQueryParams {
q[k] = v
}
Expand Down
37 changes: 37 additions & 0 deletions tfe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,43 @@ func Test_RegistryBasePath(t *testing.T) {
})
}

func Test_NewRequest(t *testing.T) {
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/get_request_with_query_param":
val := r.URL.Query().Get("include")
if val != "workspace,cost_estimate" {
t.Fatalf("unexpected include value: %q", val)
}
w.WriteHeader(http.StatusOK)
return
case "/api/v2/ping":
w.WriteHeader(http.StatusOK)
return
default:
t.Fatalf("unexpected request: %s", r.URL.String())
}
}))

t.Cleanup(func() {
testServer.Close()
})

client, err := NewClient(&Config{
Address: testServer.URL,
})
require.NoError(t, err)

t.Run("allows path to include query params", func(t *testing.T) {
request, err := client.NewRequest("GET", "/get_request_with_query_param?include=workspace,cost_estimate", nil)
require.NoError(t, err)

ctx := context.Background()
err = request.DoJSON(ctx, nil)
require.NoError(t, err)
})
}

func Test_NewRequestWithAdditionalQueryParams(t *testing.T) {
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
Expand Down
Loading