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