From ee440e65fec623fbf3e4cba05ac21d67ee6306db Mon Sep 17 00:00:00 2001 From: shreyas-goenka <88374338+shreyas-goenka@users.noreply.github.com> Date: Mon, 10 Feb 2025 17:48:05 +0530 Subject: [PATCH] Serialize all header values in acceptance tests (#2311) ## Changes Based on feedback in https://github.com/databricks/cli/pull/2296#discussion_r1946660650. Previously we only serialized the first value for a header in the requests log. Now we serialise all values for a header key. ## Tests Existing test --- .../workspace/jobs/create/out.requests.txt | 2 +- libs/testserver/server.go | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/acceptance/workspace/jobs/create/out.requests.txt b/acceptance/workspace/jobs/create/out.requests.txt index 60977e3e3..2510762db 100644 --- a/acceptance/workspace/jobs/create/out.requests.txt +++ b/acceptance/workspace/jobs/create/out.requests.txt @@ -1 +1 @@ -{"headers":{"Authorization":"Bearer [DATABRICKS_TOKEN]","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/jobs_create cmd-exec-id/[UUID] auth/pat"},"method":"POST","path":"/api/2.1/jobs/create","body":{"name":"abc"}} +{"headers":{"Authorization":["Bearer [DATABRICKS_TOKEN]"],"User-Agent":["cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/jobs_create cmd-exec-id/[UUID] auth/pat"]},"method":"POST","path":"/api/2.1/jobs/create","body":{"name":"abc"}} diff --git a/libs/testserver/server.go b/libs/testserver/server.go index 9ccf34be0..d0c340c12 100644 --- a/libs/testserver/server.go +++ b/libs/testserver/server.go @@ -31,10 +31,10 @@ type Server struct { } type Request struct { - Headers map[string]string `json:"headers,omitempty"` - Method string `json:"method"` - Path string `json:"path"` - Body any `json:"body"` + Headers http.Header `json:"headers,omitempty"` + Method string `json:"method"` + Path string `json:"path"` + Body any `json:"body"` } func New(t testutil.TestingT) *Server { @@ -109,12 +109,14 @@ func (s *Server) Handle(pattern string, handler HandlerFunc) { body, err := io.ReadAll(r.Body) assert.NoError(s.t, err) - headers := make(map[string]string) + headers := make(http.Header) for k, v := range r.Header { - if len(v) == 0 || !slices.Contains(s.IncludeRequestHeaders, k) { + if !slices.Contains(s.IncludeRequestHeaders, k) { continue } - headers[k] = v[0] + for _, vv := range v { + headers.Add(k, vv) + } } s.Requests = append(s.Requests, Request{