Skip to content

Commit

Permalink
feat(state): update dsl.State to support v3 params
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed May 22, 2018
1 parent d8bf783 commit 250baaa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions dsl/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// StateHandler is a provider function that sets up a given state before
// the provider interaction is validated
type StateHandler func(string) error
type StateHandler func(State) error

// StateHandlers is a list of StateHandler's
type StateHandlers map[string]StateHandler
Expand Down Expand Up @@ -52,12 +52,13 @@ type Message struct {
// State specifies how the system should be configured when
// verified. e.g. "user A exists"
type State struct {
Name string `json:"name"`
Name string `json:"name"`
Params map[string]interface{} `json:"params,omitempty"`
}

// Given specifies a provider state. Optional.
func (p *Message) Given(state string) *Message {
p.States = []State{State{state}}
p.States = []State{State{Name: state}}

return p
}
Expand Down
2 changes: 1 addition & 1 deletion dsl/pact.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ var messageHandler = func(messageHandlers MessageHandlers, stateHandlers StateHa
log.Printf("[WARN] state handler not found for state: %v", state.Name)
} else {
// Execute state handler
if err = sf(state.Name); err != nil {
if err = sf(state); err != nil {
log.Printf("[WARN] state handler for '%v' return error: %v", state.Name, err)
w.WriteHeader(http.StatusInternalServerError)
return
Expand Down
4 changes: 2 additions & 2 deletions examples/messages/provider/message_pact_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestMessageProvider_Success(t *testing.T) {
}

stateMappings := dsl.StateHandlers{
"user with id 127 exists": func(s string) error {
"user with id 127 exists": func(s dsl.State) error {
user = &types.User{
ID: 44,
Name: "Baz",
Expand All @@ -48,7 +48,7 @@ func TestMessageProvider_Success(t *testing.T) {

return nil
},
"no users": func(s string) error {
"no users": func(s dsl.State) error {
user = nil

return nil
Expand Down

0 comments on commit 250baaa

Please sign in to comment.