@@ -26,6 +26,13 @@ import (
2626 "github.com/stretchr/testify/require"
2727)
2828
29+ const (
30+ jsonExt = ".json"
31+ hasErrorMsg = " should have errors"
32+ noErrorMsg = " should not have errors"
33+ hasWarningMsg = " should have warnings"
34+ )
35+
2936func TestDefault_ValidatePetStore (t * testing.T ) {
3037 doc , _ := loads .Analyzed (PetStoreJSONMessage , "" )
3138 validator := NewSpecValidator (spec .MustLoadSwagger20Schema (), strfmt .Default )
@@ -72,36 +79,36 @@ func TestDefault_ValidateDefaults(t *testing.T) {
7279 }
7380
7481 for _ , tt := range tests {
75- path := filepath .Join ("fixtures" , "validation" , "default" , "valid-default-value-" + tt + ".json" )
82+ path := filepath .Join ("fixtures" , "validation" , "default" , "valid-default-value-" + tt + jsonExt )
7683 if DebugTest {
7784 t .Logf ("Testing valid default values for: %s" , path )
7885 }
7986 validator := makeSpecValidator (t , path )
8087 myDefaultValidator := & defaultValidator {SpecValidator : validator }
8188 res := myDefaultValidator .Validate ()
82- assert .Empty (t , res .Errors , tt + " should not have errors" )
89+ assert .Empty (t , res .Errors , tt + noErrorMsg )
8390
8491 // Special case: warning only
8592 if tt == "parameter-required" {
8693 warns := verifiedTestWarnings (res )
8794 assert .Contains (t , warns , "limit in query has a default value and is required as parameter" )
8895 }
8996
90- path = filepath .Join ("fixtures" , "validation" , "default" , "invalid-default-value-" + tt + ".json" )
97+ path = filepath .Join ("fixtures" , "validation" , "default" , "invalid-default-value-" + tt + jsonExt )
9198 if DebugTest {
9299 t .Logf ("Testing invalid default values for: %s" , path )
93100 }
94101
95102 validator = makeSpecValidator (t , path )
96103 myDefaultValidator = & defaultValidator {SpecValidator : validator }
97104 res = myDefaultValidator .Validate ()
98- assert .NotEmpty (t , res .Errors , tt + " should have errors" )
105+ assert .NotEmpty (t , res .Errors , tt + hasErrorMsg )
99106
100107 // Update: now we have an additional message to explain it's all about a default value
101108 // Example:
102109 // - default value for limit in query does not validate its Schema
103110 // - limit in query must be of type integer: "string"]
104- assert .True (t , len ( res .Errors ) >= 1 , tt + " should have at least 1 error" )
111+ assert .NotEmptyf (t , res .Errors , tt + " should have at least 1 error" )
105112 }
106113}
107114
0 commit comments