Skip to content

fix: fix loading values from source last req #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/app/pactproxy/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func (i *Interaction) loadValuesFromSource(constraint interactionConstraint, int
}

for i, v := range constraint.Values {
values[i], _ = jsonpath.Get(v.(string), sourceRequest)
values[i], _ = jsonpath.Get(v.(string), map[string]interface{}(sourceRequest))
}

return values, nil
Expand Down
47 changes: 47 additions & 0 deletions internal/app/pactproxy/interaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,3 +618,50 @@ func Test_getPathRegex(t *testing.T) {
})
}
}

func Test_loadValuesFromSource(t *testing.T) {
lastRequest := map[string]any{
"body": map[string]any{
"name": "sam",
},
}
tests := []*struct {
name string
sourceInteraction *Interaction
constraints interactionConstraint
want interface{}
wantErr bool
}{
{
name: "",
sourceInteraction: &Interaction{
Alias: "first-interaction",
LastRequest: lastRequest,
},
constraints: interactionConstraint{
Interaction: "first-interaction",
Path: "$.path",
Values: []interface{}{"$.body.name"},
Format: "/v1/resource/%s/subresource",
Source: "",
},
want: []interface{}{"sam"},
wantErr: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
i := &Interaction{}
inter := &Interactions{}
inter.Store(tt.sourceInteraction)
got, err := i.loadValuesFromSource(tt.constraints, inter)
if tt.wantErr {
assert.NotNil(t, err)
} else {
assert.Nil(t, err)
}
assert.Equal(t, tt.want, got)
})
}
}
Loading