Skip to content

Commit

Permalink
bonsai
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Oct 26, 2023
1 parent 593d023 commit af8d69c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
29 changes: 15 additions & 14 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func (r *httpRequest) setCookieHeader(req *http.Request, cookies map[string]map[
}
}

func (r *httpRequest) setTraceHeader(req *http.Request, s *step) error {
func (r *httpRequest) setTraceHeader(s *step) error {
if r.trace == nil || !*r.trace {
return nil
}
Expand All @@ -314,7 +314,7 @@ func (r *httpRequest) setTraceHeader(req *http.Request, s *step) error {
return err
}
// Set Trace in the header
req.Header.Set("X-Runn-Trace", string(tj))
r.headers.Set("X-Runn-Trace", string(tj))
return nil
}

Expand Down Expand Up @@ -361,6 +361,19 @@ func (rnr *httpRunner) run(ctx context.Context, r *httpRequest, s *step) error {
return err
}

// Override useCookie
if r.useCookie == nil && rnr.useCookie != nil && *rnr.useCookie {
r.useCookie = rnr.useCookie
}

// Override trace
if r.trace == nil && rnr.trace != nil && *rnr.trace {
r.trace = rnr.trace
}
if err := r.setTraceHeader(s); err != nil {
return err
}

var (
req *http.Request
res *http.Response
Expand Down Expand Up @@ -416,19 +429,7 @@ func (rnr *httpRunner) run(ctx context.Context, r *httpRequest, s *step) error {
return err
}
r.setContentTypeHeader(req)

// Override useCookie
if r.useCookie == nil && rnr.useCookie != nil && *rnr.useCookie {
r.useCookie = rnr.useCookie
}
r.setCookieHeader(req, o.store.cookies)
// Override trace
if r.trace == nil && rnr.trace != nil && *rnr.trace {
r.trace = rnr.trace
}
if err := r.setTraceHeader(req, s); err != nil {
return err
}
for k, v := range r.headers {
req.Header.Del(k)
for _, vv := range v {
Expand Down
12 changes: 4 additions & 8 deletions http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,15 +817,11 @@ func TestSetTraceHeader(t *testing.T) {
for _, tt := range tests {
t.Run(fmt.Sprintf("trace:%v", *tt.trace), func(t *testing.T) {
r := &httpRequest{
trace: tt.trace,
}
req := &http.Request{
Method: http.MethodPost,
Header: http.Header{"Content-Type": []string{"application/json"}},
headers: http.Header{},
trace: tt.trace,
}

r.setTraceHeader(req, tt.step)
got := req.Header.Get("X-Runn-Trace")
r.setTraceHeader(tt.step)

Check failure on line 823 in http_test.go

View workflow job for this annotation

GitHub Actions / Test

Error return value of `r.setTraceHeader` is not checked (errcheck)

Check failure on line 823 in http_test.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] http_test.go#L823

Error return value of `r.setTraceHeader` is not checked (errcheck)
Raw output
http_test.go:823:20: Error return value of `r.setTraceHeader` is not checked (errcheck)
			r.setTraceHeader(tt.step)
			                ^
got := r.headers.Get("X-Runn-Trace")

if got != tt.want {
t.Errorf("got %v\nwant %v", got, tt.want)
Expand Down

0 comments on commit af8d69c

Please sign in to comment.