@@ -74,7 +74,7 @@ func testCheckCachedFlag(t *testing.T, want, have bool) {
74
74
}
75
75
}
76
76
77
- func TestLocalActionsFindMetadata (t * testing.T ) {
77
+ func TestLocalActionsFindMetadataOK (t * testing.T ) {
78
78
testdir := filepath .Join ("testdata" , "action_metadata" )
79
79
proj := & Project {testdir , nil }
80
80
c := NewLocalActionsCache (proj , nil )
@@ -295,27 +295,46 @@ func TestLocalActionsNullCache(t *testing.T) {
295
295
// Error cases
296
296
297
297
func TestLocalActionsBrokenMetadata (t * testing.T ) {
298
+ tests := []struct {
299
+ spec string
300
+ want string
301
+ }{
302
+ {
303
+ spec : "./broken" ,
304
+ want : "could not parse action metadata" ,
305
+ },
306
+ {
307
+ spec : "./no_name" ,
308
+ want : "name is required in action metadata " ,
309
+ },
310
+ }
311
+
298
312
proj := & Project {filepath .Join ("testdata" , "action_metadata" ), nil }
299
313
c := NewLocalActionsCache (proj , nil )
300
- m , cached , err := c .FindMetadata ("./broken" )
301
- if err == nil {
302
- t .Fatal ("error was not returned" , m )
303
- }
304
- if ! strings .Contains (err .Error (), "could not parse action metadata" ) {
305
- t .Fatal ("unexpected error:" , err )
306
- }
307
- testCheckCachedFlag (t , false , cached )
308
314
309
- // Second try does not return error, but metadata is also nil not to show the same error from
310
- // multiple rules.
311
- m , cached , err = c .FindMetadata ("./broken" )
312
- if err != nil {
313
- t .Fatal ("error was returned at second try" , err )
314
- }
315
- if m != nil {
316
- t .Fatal ("metadata was not nil even if it does not exist" , m )
315
+ for _ , tc := range tests {
316
+ t .Run (tc .spec , func (t * testing.T ) {
317
+ m , cached , err := c .FindMetadata (tc .spec )
318
+ if err == nil {
319
+ t .Fatal ("error was not returned" , m )
320
+ }
321
+ if ! strings .Contains (err .Error (), tc .want ) {
322
+ t .Fatalf ("expected error message %q to contain %q" , err , tc .want )
323
+ }
324
+ testCheckCachedFlag (t , false , cached )
325
+
326
+ // Second try does not return error, but metadata is also nil not to show the same error from
327
+ // multiple rules.
328
+ m , cached , err = c .FindMetadata (tc .spec )
329
+ if err != nil {
330
+ t .Fatal ("error was returned at second try" , err )
331
+ }
332
+ if m != nil {
333
+ t .Fatal ("metadata was not nil even if it does not exist" , m )
334
+ }
335
+ testCheckCachedFlag (t , true , cached )
336
+ })
317
337
}
318
- testCheckCachedFlag (t , true , cached )
319
338
}
320
339
321
340
func TestLocalActionsDuplicateInputsOutputs (t * testing.T ) {
0 commit comments