Skip to content

Commit e97cd2d

Browse files
committed
fix: value from provider state needed explicit content-type header
1 parent 6ffeb4e commit e97cd2d

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

examples/v3/pacts/V3Consumer-V3Provider.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{
1010
"name": "User foo exists",
1111
"params": {
12-
"id": "foo"
12+
"some": "param"
1313
}
1414
}
1515
],

examples/v3/provider_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestV3HTTPProvider(t *testing.T) {
5757
// ... do something
5858

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

6262
// return nil, nil
6363
},

v3/http_verifier.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ func stateHandlerMiddleware(stateHandlers StateHandlers) proxy.Middleware {
220220
return
221221
}
222222

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

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

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

258+
w.Header().Add("content-type", "application/json")
254259
w.Write(resBody)
255260
}
256261
}

0 commit comments

Comments
 (0)