Skip to content

Commit

Permalink
rearrange headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Michael committed Dec 12, 2017
1 parent fec602d commit d7cbed2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions assured/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ func decodeAssuredCall(ctx context.Context, req *http.Request) (interface{}, err
// Set headers
headers := map[string]string{}
for key, value := range req.Header {
if !strings.HasPrefix(key, "Assured") {
headers[key] = value[0]
}
headers[key] = value[0]
}
ac.Headers = headers

Expand All @@ -145,7 +143,9 @@ func encodeAssuredCall(ctx context.Context, w http.ResponseWriter, i interface{}
case *Call:
w.WriteHeader(resp.StatusCode)
for key, value := range resp.Headers {
w.Header().Set(key, value)
if !strings.HasPrefix(key, "Assured") {
w.Header().Set(key, value)
}
}
w.Write([]byte(resp.String()))
case []*Call:
Expand Down
8 changes: 4 additions & 4 deletions assured/bindings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func TestDecodeAssuredCallStatus(t *testing.T) {
Path: "test/assured",
StatusCode: http.StatusForbidden,
Method: http.MethodGet,
Headers: map[string]string{},
Headers: map[string]string{"Assured-Status": "403"},
}
testDecode := func(resp http.ResponseWriter, req *http.Request) {
c, err := decodeAssuredCall(ctx, req)
Expand Down Expand Up @@ -180,7 +180,7 @@ func TestDecodeAssuredCallStatusFailure(t *testing.T) {
Path: "test/assured",
StatusCode: http.StatusOK,
Method: http.MethodGet,
Headers: map[string]string{},
Headers: map[string]string{"Assured-Status": "four oh three"},
}
testDecode := func(resp http.ResponseWriter, req *http.Request) {
c, err := decodeAssuredCall(ctx, req)
Expand Down Expand Up @@ -208,7 +208,7 @@ func TestEncodeAssuredCall(t *testing.T) {
StatusCode: http.StatusCreated,
Method: http.MethodPost,
Response: []byte(`{"assured": true}`),
Headers: map[string]string{"Content-Length": "19", "User-Agent": "Go-http-client/1.1", "Accept-Encoding": "gzip"},
Headers: map[string]string{"Content-Length": "19", "User-Agent": "Go-http-client/1.1", "Accept-Encoding": "gzip", "Assured-Status": "403"},
}
resp := httptest.NewRecorder()

Expand All @@ -220,6 +220,7 @@ func TestEncodeAssuredCall(t *testing.T) {
require.Equal(t, "19", resp.Header().Get("Content-Length"))
require.Equal(t, "Go-http-client/1.1", resp.Header().Get("User-Agent"))
require.Equal(t, "gzip", resp.Header().Get("Accept-Encoding"))
require.Empty(t, resp.Header().Get("Assured-Status"))
}

func TestEncodeAssuredCalls(t *testing.T) {
Expand All @@ -231,7 +232,6 @@ func TestEncodeAssuredCalls(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "application/json", resp.HeaderMap.Get("Content-Type"))
require.JSONEq(t, string(expected), resp.Body.String())
// require.Equal(t, `[{"path":"test/assured","method":"GET","status_code":200,"response":"eyJhc3N1cmVkIjogdHJ1ZX0="},{"path":"test/assured","method":"GET","status_code":409,"response":"ZXJyb3I="}]`+"\n", resp.Body.String())
}

//go-rest-assured test vars
Expand Down

0 comments on commit d7cbed2

Please sign in to comment.