@@ -21,6 +21,7 @@ import (
21
21
"time"
22
22
23
23
"github.com/stretchr/testify/assert"
24
+ "github.com/stretchr/testify/require"
24
25
25
26
"github.com/dapr/kit/config"
26
27
"github.com/dapr/kit/ptr"
@@ -187,7 +188,7 @@ func TestDecode(t *testing.T) {
187
188
t .Run (name , func (t * testing.T ) {
188
189
var actual testConfig
189
190
err := config .Decode (tc , & actual )
190
- assert .NoError (t , err )
191
+ require .NoError (t , err )
191
192
assert .Equal (t , expected , actual )
192
193
})
193
194
}
@@ -231,61 +232,60 @@ func TestDecodeErrors(t *testing.T) {
231
232
"string" : 1234 ,
232
233
"stringPtr" : 1234 ,
233
234
}, & actual )
234
- if assert .Error (t , err ) {
235
- errMsg := err .Error ()
236
- expectedNumErrors := 32
237
- expectedPrefix := " error(s) decoding:"
238
- assert .True (t , strings .HasPrefix (errMsg , fmt .Sprintf ("%d%s" , expectedNumErrors , expectedPrefix )), errMsg )
239
- prefixIndex := strings .Index (errMsg , expectedPrefix )
240
- if assert .True (t , prefixIndex != - 1 ) {
241
- errMsg = errMsg [prefixIndex + len (expectedPrefix ):]
242
- errMsg = strings .TrimSpace (errMsg )
243
- errors := strings .Split (errMsg , "\n " )
244
- errorSet := make (map [string ]struct {}, len (errors ))
245
- for _ , e := range errors {
246
- errorSet [e ] = struct {}{}
247
- }
248
- expectedErrors := []string {
249
- "* error decoding 'int': invalid int \" -badval\" " ,
250
- "* error decoding 'intPtr': invalid int \" -badval\" " ,
251
- "* error decoding 'int16': invalid int16 \" -badval\" " ,
252
- "* error decoding 'int16Ptr': invalid int16 \" -badval\" " ,
253
- "* error decoding 'int32': invalid int32 \" -badval\" " ,
254
- "* error decoding 'int32Ptr': invalid int32 \" -badval\" " ,
255
- "* error decoding 'int64': invalid int64 \" -badval\" " ,
256
- "* error decoding 'int64Ptr': invalid int64 \" -badval\" " ,
257
- "* error decoding 'int8': invalid int8 \" -badval\" " ,
258
- "* error decoding 'int8Ptr': invalid int8 \" -badval\" " ,
259
- "* error decoding 'uint': invalid uint \" -9999\" " ,
260
- "* error decoding 'uintPtr': invalid uint \" -9999\" " ,
261
- "* error decoding 'uint64': invalid uint64 \" -1234\" " ,
262
- "* error decoding 'uint64Ptr': invalid uint64 \" -1234\" " ,
263
- "* error decoding 'uint32': invalid uint32 \" -5678\" " ,
264
- "* error decoding 'uint32Ptr': invalid uint32 \" -5678\" " ,
265
- "* error decoding 'uint16': invalid uint16 \" -9012\" " ,
266
- "* error decoding 'uint16Ptr': invalid uint16 \" -9012\" " ,
267
- "* error decoding 'byte': invalid uint8 \" -1\" " ,
268
- "* error decoding 'bytePtr': invalid uint8 \" -1\" " ,
269
- "* error decoding 'float32': invalid float32 \" badval.5\" " ,
270
- "* error decoding 'float32Ptr': invalid float32 \" badval.5\" " ,
271
- "* error decoding 'float64': invalid float64 \" badval.5\" " ,
272
- "* error decoding 'float64Ptr': invalid float64 \" badval.5\" " ,
273
- "* error decoding 'duration': invalid duration \" badval\" " ,
274
- "* error decoding 'durationPtr': invalid duration \" badval\" " ,
275
- "* error decoding 'time': invalid time \" badval\" " ,
276
- "* error decoding 'timePtr': invalid time \" badval\" " ,
277
- "* error decoding 'decoded': invalid Decoded \" badval\" : strconv.Atoi: parsing \" badval\" : invalid syntax" ,
278
- "* error decoding 'decodedPtr': invalid Decoded \" badval\" : strconv.Atoi: parsing \" badval\" : invalid syntax" ,
279
- "* error decoding 'bool': invalid bool \" badval\" " ,
280
- "* error decoding 'boolPtr': invalid bool \" badval\" " ,
281
- }
282
- for _ , expectedError := range expectedErrors {
283
- assert .Contains (t , errors , expectedError )
284
- delete (errorSet , expectedError )
285
- }
286
- assert .Empty (t , errorSet )
287
- }
235
+ require .Error (t , err )
236
+
237
+ errMsg := err .Error ()
238
+ expectedNumErrors := 32
239
+ expectedPrefix := " error(s) decoding:"
240
+ assert .True (t , strings .HasPrefix (errMsg , fmt .Sprintf ("%d%s" , expectedNumErrors , expectedPrefix )), errMsg )
241
+ prefixIndex := strings .Index (errMsg , expectedPrefix )
242
+ require .NotEqual (t , - 1 , prefixIndex )
243
+ errMsg = errMsg [prefixIndex + len (expectedPrefix ):]
244
+ errMsg = strings .TrimSpace (errMsg )
245
+ errors := strings .Split (errMsg , "\n " )
246
+ errorSet := make (map [string ]struct {}, len (errors ))
247
+ for _ , e := range errors {
248
+ errorSet [e ] = struct {}{}
249
+ }
250
+ expectedErrors := []string {
251
+ "* error decoding 'int': invalid int \" -badval\" " ,
252
+ "* error decoding 'intPtr': invalid int \" -badval\" " ,
253
+ "* error decoding 'int16': invalid int16 \" -badval\" " ,
254
+ "* error decoding 'int16Ptr': invalid int16 \" -badval\" " ,
255
+ "* error decoding 'int32': invalid int32 \" -badval\" " ,
256
+ "* error decoding 'int32Ptr': invalid int32 \" -badval\" " ,
257
+ "* error decoding 'int64': invalid int64 \" -badval\" " ,
258
+ "* error decoding 'int64Ptr': invalid int64 \" -badval\" " ,
259
+ "* error decoding 'int8': invalid int8 \" -badval\" " ,
260
+ "* error decoding 'int8Ptr': invalid int8 \" -badval\" " ,
261
+ "* error decoding 'uint': invalid uint \" -9999\" " ,
262
+ "* error decoding 'uintPtr': invalid uint \" -9999\" " ,
263
+ "* error decoding 'uint64': invalid uint64 \" -1234\" " ,
264
+ "* error decoding 'uint64Ptr': invalid uint64 \" -1234\" " ,
265
+ "* error decoding 'uint32': invalid uint32 \" -5678\" " ,
266
+ "* error decoding 'uint32Ptr': invalid uint32 \" -5678\" " ,
267
+ "* error decoding 'uint16': invalid uint16 \" -9012\" " ,
268
+ "* error decoding 'uint16Ptr': invalid uint16 \" -9012\" " ,
269
+ "* error decoding 'byte': invalid uint8 \" -1\" " ,
270
+ "* error decoding 'bytePtr': invalid uint8 \" -1\" " ,
271
+ "* error decoding 'float32': invalid float32 \" badval.5\" " ,
272
+ "* error decoding 'float32Ptr': invalid float32 \" badval.5\" " ,
273
+ "* error decoding 'float64': invalid float64 \" badval.5\" " ,
274
+ "* error decoding 'float64Ptr': invalid float64 \" badval.5\" " ,
275
+ "* error decoding 'duration': invalid duration \" badval\" " ,
276
+ "* error decoding 'durationPtr': invalid duration \" badval\" " ,
277
+ "* error decoding 'time': invalid time \" badval\" " ,
278
+ "* error decoding 'timePtr': invalid time \" badval\" " ,
279
+ "* error decoding 'decoded': invalid Decoded \" badval\" : strconv.Atoi: parsing \" badval\" : invalid syntax" ,
280
+ "* error decoding 'decodedPtr': invalid Decoded \" badval\" : strconv.Atoi: parsing \" badval\" : invalid syntax" ,
281
+ "* error decoding 'bool': invalid bool \" badval\" " ,
282
+ "* error decoding 'boolPtr': invalid bool \" badval\" " ,
283
+ }
284
+ for _ , expectedError := range expectedErrors {
285
+ assert .Contains (t , errors , expectedError )
286
+ delete (errorSet , expectedError )
288
287
}
288
+ assert .Empty (t , errorSet )
289
289
}
290
290
291
291
func getTimeVal () time.Time {
0 commit comments