@@ -23,7 +23,7 @@ import (
23
23
"github.com/arduino/arduino-lint/internal/rule/schema/testdata"
24
24
"github.com/arduino/go-properties-orderedmap"
25
25
"github.com/ory/jsonschema/v3"
26
- "github.com/stretchr/testify/require "
26
+ "github.com/stretchr/testify/assert "
27
27
)
28
28
29
29
var validMap = map [string ]string {
@@ -50,27 +50,27 @@ func init() {
50
50
}
51
51
52
52
func TestCompile (t * testing.T ) {
53
- require .Panics (t , func () {
53
+ assert .Panics (t , func () {
54
54
Compile ("valid-schema-with-references.json" , []string {"nonexistent.json" }, testdata .Asset )
55
55
})
56
56
57
- require .Panics (t , func () {
57
+ assert .Panics (t , func () {
58
58
Compile ("valid-schema-with-references.json" , []string {"schema-without-id.json" }, testdata .Asset )
59
59
})
60
60
61
- require .Panics (t , func () {
61
+ assert .Panics (t , func () {
62
62
Compile ("invalid-schema.json" , []string {}, testdata .Asset )
63
63
})
64
64
65
- require .Panics (t , func () {
65
+ assert .Panics (t , func () {
66
66
Compile ("valid-schema-with-references.json" , []string {}, testdata .Asset )
67
67
})
68
68
69
- require .NotPanics (t , func () {
69
+ assert .NotPanics (t , func () {
70
70
Compile ("valid-schema.json" , []string {}, testdata .Asset )
71
71
})
72
72
73
- require .NotPanics (t , func () {
73
+ assert .NotPanics (t , func () {
74
74
Compile (
75
75
"valid-schema-with-references.json" ,
76
76
[]string {
@@ -86,134 +86,134 @@ func TestValidate(t *testing.T) {
86
86
schemaObject := Compile ("valid-schema.json" , []string {}, testdata .Asset )
87
87
propertiesMap := properties .NewFromHashmap (validMap )
88
88
validationResult := Validate (general .PropertiesToMap (propertiesMap , 0 ), schemaObject )
89
- require .Nil (t , validationResult .Result )
89
+ assert .Nil (t , validationResult .Result )
90
90
91
91
validationResult = Validate (general .PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
92
- require .Nil (t , validationResult .Result )
92
+ assert .Nil (t , validationResult .Result )
93
93
94
94
propertiesMap .Set ("property1" , "a" )
95
95
validationResult = Validate (general .PropertiesToMap (propertiesMap , 0 ), schemaObject )
96
- require .Equal (t , "#/property1" , validationResult .Result .InstancePtr )
97
- require .Equal (t , "#/properties/property1/minLength" , validationResult .Result .SchemaPtr )
96
+ assert .Equal (t , "#/property1" , validationResult .Result .InstancePtr )
97
+ assert .Equal (t , "#/properties/property1/minLength" , validationResult .Result .SchemaPtr )
98
98
}
99
99
100
100
func TestRequiredPropertyMissing (t * testing.T ) {
101
101
propertiesMap := properties .NewFromHashmap (validMap )
102
102
validationResult := Validate (general .PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
103
- require .False (t , RequiredPropertyMissing ("property1" , validationResult ))
103
+ assert .False (t , RequiredPropertyMissing ("property1" , validationResult ))
104
104
105
105
propertiesMap .Remove ("property1" )
106
106
validationResult = Validate (general .PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
107
- require .True (t , RequiredPropertyMissing ("property1" , validationResult ))
107
+ assert .True (t , RequiredPropertyMissing ("property1" , validationResult ))
108
108
}
109
109
110
110
func TestPropertyPatternMismatch (t * testing.T ) {
111
111
propertiesMap := properties .NewFromHashmap (validMap )
112
112
validationResult := Validate (general .PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
113
- require .False (t , PropertyPatternMismatch ("property2" , validationResult ))
113
+ assert .False (t , PropertyPatternMismatch ("property2" , validationResult ))
114
114
115
115
propertiesMap .Set ("property2" , "fOo" )
116
116
validationResult = Validate (general .PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
117
- require .True (t , PropertyPatternMismatch ("property2" , validationResult ))
117
+ assert .True (t , PropertyPatternMismatch ("property2" , validationResult ))
118
118
119
- require .False (t , PropertyPatternMismatch ("property1" , validationResult ))
119
+ assert .False (t , PropertyPatternMismatch ("property1" , validationResult ))
120
120
}
121
121
122
122
func TestPropertyLessThanMinLength (t * testing.T ) {
123
123
propertiesMap := properties .NewFromHashmap (validMap )
124
124
validationResult := Validate (general .PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
125
- require .False (t , PropertyLessThanMinLength ("property1" , validationResult ))
125
+ assert .False (t , PropertyLessThanMinLength ("property1" , validationResult ))
126
126
127
127
propertiesMap .Set ("property1" , "a" )
128
128
validationResult = Validate (general .PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
129
- require .True (t , PropertyLessThanMinLength ("property1" , validationResult ))
129
+ assert .True (t , PropertyLessThanMinLength ("property1" , validationResult ))
130
130
}
131
131
132
132
func TestPropertyGreaterThanMaxLength (t * testing.T ) {
133
133
propertiesMap := properties .NewFromHashmap (validMap )
134
134
validationResult := Validate (general .PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
135
- require .False (t , PropertyGreaterThanMaxLength ("property1" , validationResult ))
135
+ assert .False (t , PropertyGreaterThanMaxLength ("property1" , validationResult ))
136
136
137
137
propertiesMap .Set ("property1" , "12345" )
138
138
validationResult = Validate (general .PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
139
- require .True (t , PropertyGreaterThanMaxLength ("property1" , validationResult ))
139
+ assert .True (t , PropertyGreaterThanMaxLength ("property1" , validationResult ))
140
140
}
141
141
142
142
func TestPropertyEnumMismatch (t * testing.T ) {
143
143
propertiesMap := properties .NewFromHashmap (validMap )
144
144
validationResult := Validate (general .PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
145
- require .False (t , PropertyEnumMismatch ("property3" , validationResult ))
145
+ assert .False (t , PropertyEnumMismatch ("property3" , validationResult ))
146
146
147
147
propertiesMap .Set ("property3" , "invalid" )
148
148
validationResult = Validate (general .PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
149
- require .True (t , PropertyEnumMismatch ("property3" , validationResult ))
149
+ assert .True (t , PropertyEnumMismatch ("property3" , validationResult ))
150
150
}
151
151
152
152
func TestPropertyDependenciesMissing (t * testing.T ) {
153
153
propertiesMap := properties .NewFromHashmap (validMap )
154
154
validationResult := Validate (general .PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
155
- require .False (t , PropertyDependenciesMissing ("dependentProperty" , validationResult ))
155
+ assert .False (t , PropertyDependenciesMissing ("dependentProperty" , validationResult ))
156
156
157
157
propertiesMap .Remove ("dependencyProperty" )
158
158
validationResult = Validate (general .PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
159
- require .True (t , PropertyDependenciesMissing ("dependentProperty" , validationResult ))
159
+ assert .True (t , PropertyDependenciesMissing ("dependentProperty" , validationResult ))
160
160
}
161
161
162
162
func TestMisspelledOptionalPropertyFound (t * testing.T ) {
163
163
propertiesMap := properties .NewFromHashmap (validMap )
164
164
validationResult := Validate (general .PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
165
- require .False (t , MisspelledOptionalPropertyFound (validationResult ))
165
+ assert .False (t , MisspelledOptionalPropertyFound (validationResult ))
166
166
167
167
propertiesMap .Set ("porperties" , "foo" )
168
168
validationResult = Validate (general .PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
169
- require .True (t , MisspelledOptionalPropertyFound (validationResult ))
169
+ assert .True (t , MisspelledOptionalPropertyFound (validationResult ))
170
170
}
171
171
172
172
func TestValidationErrorMatch (t * testing.T ) {
173
173
propertiesMap := properties .NewFromHashmap (validMap )
174
174
validationResult := Validate (general .PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
175
- require .False (t , ValidationErrorMatch ("" , "" , "" , "" , validationResult ))
175
+ assert .False (t , ValidationErrorMatch ("" , "" , "" , "" , validationResult ))
176
176
177
177
propertiesMap .Set ("property2" , "fOo" )
178
178
validationResult = Validate (general .PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
179
- require .False (t , ValidationErrorMatch ("nomatch" , "nomatch" , "nomatch" , "nomatch" , validationResult ))
180
- require .False (t , ValidationErrorMatch ("^#/property2$" , "nomatch" , "nomatch" , "nomatch" , validationResult ))
181
- require .False (t , ValidationErrorMatch ("^#/property2$" , "/pattern$" , "nomatch" , "nomatch" , validationResult ))
182
- require .False (t , ValidationErrorMatch ("^#/property2$" , "/pattern$" , `^\^\[a-z\]\+\$$` , "nomatch" , validationResult ))
183
- require .True (t , ValidationErrorMatch ("^#/property2$" , "/pattern$" , `^"\^\[a-z\]\+\$"$` , "" , validationResult ))
184
- require .True (t , ValidationErrorMatch ("" , "" , "" , "" , validationResult ))
179
+ assert .False (t , ValidationErrorMatch ("nomatch" , "nomatch" , "nomatch" , "nomatch" , validationResult ))
180
+ assert .False (t , ValidationErrorMatch ("^#/property2$" , "nomatch" , "nomatch" , "nomatch" , validationResult ))
181
+ assert .False (t , ValidationErrorMatch ("^#/property2$" , "/pattern$" , "nomatch" , "nomatch" , validationResult ))
182
+ assert .False (t , ValidationErrorMatch ("^#/property2$" , "/pattern$" , `^\^\[a-z\]\+\$$` , "nomatch" , validationResult ))
183
+ assert .True (t , ValidationErrorMatch ("^#/property2$" , "/pattern$" , `^"\^\[a-z\]\+\$"$` , "" , validationResult ))
184
+ assert .True (t , ValidationErrorMatch ("" , "" , "" , "" , validationResult ))
185
185
186
186
propertiesMap .Set ("property3" , "bAz" )
187
187
validationResult = Validate (general .PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
188
- require .True (t , ValidationErrorMatch ("^#/property3$" , "/pattern$" , "" , "" , validationResult ), "Match pointer below logic inversion keyword" )
188
+ assert .True (t , ValidationErrorMatch ("^#/property3$" , "/pattern$" , "" , "" , validationResult ), "Match pointer below logic inversion keyword" )
189
189
190
190
propertiesMap = properties .NewFromHashmap (validMap )
191
191
propertiesMap .Remove ("property1" )
192
192
validationResult = Validate (general .PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
193
- require .False (t , ValidationErrorMatch ("nomatch" , "nomatch" , "nomatch" , "nomatch" , validationResult ))
194
- require .True (t , ValidationErrorMatch ("" , "" , "" , "^#/property1$" , validationResult ))
193
+ assert .False (t , ValidationErrorMatch ("nomatch" , "nomatch" , "nomatch" , "nomatch" , validationResult ))
194
+ assert .True (t , ValidationErrorMatch ("" , "" , "" , "^#/property1$" , validationResult ))
195
195
}
196
196
197
197
func Test_loadReferencedSchema (t * testing.T ) {
198
198
compiler := jsonschema .NewCompiler ()
199
199
200
- require .Panics (
200
+ assert .Panics (
201
201
t ,
202
202
func () {
203
203
loadReferencedSchema (compiler , "nonexistent.json" , testdata .Asset )
204
204
},
205
205
)
206
- require .Error (t , loadReferencedSchema (compiler , "schema-without-id.json" , testdata .Asset ))
207
- require .Nil (t , loadReferencedSchema (compiler , "referenced-schema-2.json" , testdata .Asset ))
206
+ assert .Error (t , loadReferencedSchema (compiler , "schema-without-id.json" , testdata .Asset ))
207
+ assert .Nil (t , loadReferencedSchema (compiler , "referenced-schema-2.json" , testdata .Asset ))
208
208
}
209
209
210
210
func Test_schemaID (t * testing.T ) {
211
211
_ , err := schemaID ("schema-without-id.json" , testdata .Asset )
212
- require .NotNil (t , err )
212
+ assert .NotNil (t , err )
213
213
214
214
id , err := schemaID ("valid-schema.json" , testdata .Asset )
215
- require .Equal (t , "https://raw.githubusercontent.com/arduino/arduino-lint/main/internal/rule/schema/testdata/schema-with-references.json" , id )
216
- require .Nil (t , err )
215
+ assert .Equal (t , "https://raw.githubusercontent.com/arduino/arduino-lint/main/internal/rule/schema/testdata/schema-with-references.json" , id )
216
+ assert .Nil (t , err )
217
217
}
218
218
219
219
func Test_validationErrorSchemaPointerValue (t * testing.T ) {
@@ -227,17 +227,17 @@ func Test_validationErrorSchemaPointerValue(t *testing.T) {
227
227
228
228
schemaPointerValueInterface := validationErrorSchemaPointerValue (validationError )
229
229
schemaPointerValue , ok := schemaPointerValueInterface .(string )
230
- require .True (t , ok )
231
- require .Equal (t , "^[a-z]+$" , schemaPointerValue )
230
+ assert .True (t , ok )
231
+ assert .Equal (t , "^[a-z]+$" , schemaPointerValue )
232
232
}
233
233
234
234
func Test_validationErrorContextMatch (t * testing.T ) {
235
235
validationError := jsonschema.ValidationError {
236
236
Context : nil ,
237
237
}
238
238
239
- require .True (t , validationErrorContextMatch (regexp .MustCompile (".*" ), & validationError ))
240
- require .False (t , validationErrorContextMatch (regexp .MustCompile ("foo" ), & validationError ))
239
+ assert .True (t , validationErrorContextMatch (regexp .MustCompile (".*" ), & validationError ))
240
+ assert .False (t , validationErrorContextMatch (regexp .MustCompile ("foo" ), & validationError ))
241
241
242
242
validationError .Context = & jsonschema.ValidationErrorContextRequired {
243
243
Missing : []string {
@@ -246,6 +246,6 @@ func Test_validationErrorContextMatch(t *testing.T) {
246
246
},
247
247
}
248
248
249
- require .True (t , validationErrorContextMatch (regexp .MustCompile ("^#/bar$" ), & validationError ))
250
- require .False (t , validationErrorContextMatch (regexp .MustCompile ("nomatch" ), & validationError ))
249
+ assert .True (t , validationErrorContextMatch (regexp .MustCompile ("^#/bar$" ), & validationError ))
250
+ assert .False (t , validationErrorContextMatch (regexp .MustCompile ("nomatch" ), & validationError ))
251
251
}
0 commit comments