Skip to content

Commit

Permalink
fix: value from provider state needed explicit content-type header
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Mar 13, 2021
1 parent 6ffeb4e commit e97cd2d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/v3/pacts/V3Consumer-V3Provider.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{
"name": "User foo exists",
"params": {
"id": "foo"
"some": "param"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion examples/v3/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestV3HTTPProvider(t *testing.T) {
// ... do something

// Optionally (if there are generators in the pact) return provider state values to be used in the verification (only )
return v3.ProviderStateV3Response{"id": "bar"}, nil
return v3.ProviderStateV3Response{"uuid": "1234"}, nil

// return nil, nil
},
Expand Down
5 changes: 5 additions & 0 deletions v3/http_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ func stateHandlerMiddleware(stateHandlers StateHandlers) proxy.Middleware {
return
}

// TODO: update rust code - params should be in a sub-property, to avoid top-level key conflicts
// i.e. it's possible action/state are actually something a users wants to supply
delete(params, "action")
delete(params, "state")
state.Params = params
Expand All @@ -242,7 +244,9 @@ func stateHandlerMiddleware(stateHandlers StateHandlers) proxy.Middleware {

// Return provider state values for generator
if res != nil {
log.Println("[TRACE] returning values from provider state (raw)", res)
resBody, err := json.Marshal(res)
log.Println("[TRACE] returning values from provider state (JSON)", string(resBody))

if err != nil {
log.Printf("[ERROR] state handler for '%v' errored: %v", state.State, err)
Expand All @@ -251,6 +255,7 @@ func stateHandlerMiddleware(stateHandlers StateHandlers) proxy.Middleware {
return
}

w.Header().Add("content-type", "application/json")
w.Write(resBody)
}
}
Expand Down

0 comments on commit e97cd2d

Please sign in to comment.