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
1 change: 1 addition & 0 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (c *Client) doRequestOnce(ctx context.Context, endpoint string, bodyBytes [
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-api-token", c.apiKey)
req.Header.Set("x-source", "terraform")

resp, err := c.httpClient.Do(req)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion internal/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ func newTestClient(apiKey, baseURL string) *Client {
}

func TestDoRequest_SetsAuthAndContentTypeHeaders(t *testing.T) {
var gotAPIToken, gotContentType, gotMethod string
var gotAPIToken, gotContentType, gotSource, gotMethod string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gotAPIToken = r.Header.Get("x-api-token")
gotContentType = r.Header.Get("Content-Type")
gotSource = r.Header.Get("x-source")
gotMethod = r.Method
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("{}"))
Expand All @@ -41,6 +42,9 @@ func TestDoRequest_SetsAuthAndContentTypeHeaders(t *testing.T) {
if gotMethod != http.MethodPost {
t.Errorf("method = %q, want %q", gotMethod, http.MethodPost)
}
if gotSource != "terraform" {
t.Errorf("x-source = %q, want %q", gotSource, "terraform")
}
}

func TestDoRequest_Returns4xxAsAPIError(t *testing.T) {
Expand Down
Loading