Skip to content

Commit 95acf44

Browse files
fixup: pr comments - to be squashed into 1st commit
1 parent b59a60b commit 95acf44

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

internal/app/pactproxy/constraint.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (i interactionConstraint) Key() string {
1919
return strings.Join([]string{i.Interaction, i.Path}, "_")
2020
}
2121

22-
func (i interactionConstraint) Check(expectedValues []interface{}, actualValue interface{}) error {
22+
func (i interactionConstraint) check(expectedValues []interface{}, actualValue interface{}) error {
2323
if i.Format == fmtLen {
2424
if len(expectedValues) != 1 {
2525
return fmt.Errorf(

internal/app/pactproxy/interaction.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func (i *Interaction) addJSONConstraintsFromPact(path string, matchingRules map[
278278
case []interface{}:
279279
// Create constraints for each element in the array. This allows matching rules to override them.
280280
for j := range val {
281-
i.addJSONConstraintsFromPact(fmt.Sprintf("%v[%v]", path, j), matchingRules, val[j])
281+
i.addJSONConstraintsFromPact(fmt.Sprintf("%s[%d]", path, j), matchingRules, val[j])
282282
}
283283
// Length constraint so that requests with additional elements at the end of the array will not match
284284
i.AddConstraint(interactionConstraint{
@@ -345,26 +345,26 @@ func (i *Interaction) EvaluateConstraints(request requestDocument, interactions
345345
i.mu.RLock()
346346
defer i.mu.RUnlock()
347347
for _, constraint := range i.constraints {
348-
values := constraint.Values
348+
expected := constraint.Values
349349
if constraint.Source != "" {
350350
var err error
351-
values, err = i.loadValuesFromSource(constraint, interactions)
351+
expected, err = i.loadValuesFromSource(constraint, interactions)
352352
if err != nil {
353353
violations = append(violations, err.Error())
354354
result = false
355355
continue
356356
}
357357
}
358358

359-
val, err := jsonpath.Get(request.encodeValues(constraint.Path), map[string]interface{}(request))
359+
actual, err := jsonpath.Get(request.encodeValues(constraint.Path), map[string]interface{}(request))
360360
if err != nil {
361361
violations = append(violations,
362362
fmt.Sprintf("constraint path %q cannot be resolved within request: %q", constraint.Path, err))
363363
result = false
364364
continue
365365
}
366366

367-
if err := constraint.Check(values, val); err != nil {
367+
if err := constraint.check(expected, actual); err != nil {
368368
violations = append(violations, err.Error())
369369
result = false
370370
}

0 commit comments

Comments
 (0)