fix: contains assertion bug; feat: add type_match, contained_by, string_equals assertion methods

Change-Id: Icb15fe33a58d1ff69991435bbe70c3cd53bb8dea
This commit is contained in:
buyuxiang
2021-12-30 14:47:10 +08:00
parent 10fbc7f5c4
commit b22a5d2af0
3 changed files with 71 additions and 3 deletions

View File

@@ -35,6 +35,28 @@ func (s *StepRequestValidation) AssertEqual(jmesPath string, expected interface{
return s
}
func (s *StepRequestValidation) AssertContains(jmesPath string, expected interface{}, msg string) *StepRequestValidation {
v := Validator{
Check: jmesPath,
Assert: "contains",
Expect: expected,
Message: msg,
}
s.step.Validators = append(s.step.Validators, v)
return s
}
func (s *StepRequestValidation) AssertTypeMatch(jmesPath string, expected interface{}, msg string) *StepRequestValidation {
v := Validator{
Check: jmesPath,
Assert: "type_match",
Expect: expected,
Message: msg,
}
s.step.Validators = append(s.step.Validators, v)
return s
}
func (s *StepRequestValidation) AssertStartsWith(jmesPath string, expected interface{}, msg string) *StepRequestValidation {
v := Validator{
Check: jmesPath,
@@ -67,3 +89,25 @@ func (s *StepRequestValidation) AssertLengthEqual(jmesPath string, expected inte
s.step.Validators = append(s.step.Validators, v)
return s
}
func (s *StepRequestValidation) AssertContainedBy(jmesPath string, expected interface{}, msg string) *StepRequestValidation {
v := Validator{
Check: jmesPath,
Assert: "contained_by",
Expect: expected,
Message: msg,
}
s.step.Validators = append(s.step.Validators, v)
return s
}
func (s *StepRequestValidation) AssertStringEqual(jmesPath string, expected interface{}, msg string) *StepRequestValidation {
v := Validator{
Check: jmesPath,
Assert: "string_equals",
Expect: expected,
Message: msg,
}
s.step.Validators = append(s.step.Validators, v)
return s
}