@@ -5,49 +5,62 @@ import (
55
66 "github.com/stretchr/testify/assert"
77 "github.com/stretchr/testify/require"
8+ "go.bug.st/f"
89
910 "github.com/arduino/go-paths-helper"
1011
1112 "github.com/arduino/arduino-app-cli/internal/orchestrator/bricksindex"
1213)
1314
14- func TestValidateAppDescriptor (t * testing.T ) {
15+ func TestValidateBricksOnAppDescriptor (t * testing.T ) {
1516 bricksIndex , err := bricksindex .GenerateBricksIndexFromFile (paths .New ("testdata/validator" ))
1617 require .Nil (t , err )
1718
18- t .Run ("valid app descriptor with no bricks" , func (t * testing.T ) {
19- app , err := ParseDescriptorFile (paths .New ("testdata/validator/no-bricks-app.yaml" ))
20- require .NoError (t , err )
21- err = ValidateAppDescriptor (app , bricksIndex )
22- assert .NoError (t , err )
23- })
24-
25- t .Run ("valid app descriptor with empty list of bricks" , func (t * testing.T ) {
26- app , err := ParseDescriptorFile (paths .New ("testdata/validator/empty-bricks-app.yaml" ))
27- require .NoError (t , err )
28- err = ValidateAppDescriptor (app , bricksIndex )
29- assert .NoError (t , err )
30- })
31-
32- t .Run ("invalid app descriptor with missing required variable" , func (t * testing.T ) {
33- app , err := ParseDescriptorFile (paths .New ("testdata/validator/missing-required-app.yaml" ))
34- require .NoError (t , err )
35- err = ValidateAppDescriptor (app , bricksIndex )
36- assert .Equal (t , "variable \" ARDUINO_DEVICE_ID\" is required by brick \" arduino:arduino_cloud\" " , err .Error ())
37- })
38-
39- t .Run ("invalid app descriptor with a missing required variable among two" , func (t * testing.T ) {
40- app , err := ParseDescriptorFile (paths .New ("testdata/validator/mixed-required-app.yaml" ))
41- require .NoError (t , err )
42- err = ValidateAppDescriptor (app , bricksIndex )
43- assert .Equal (t , "variable \" ARDUINO_SECRET\" is required by brick \" arduino:arduino_cloud\" " , err .Error ())
44- })
45-
46- t .Run ("invalid app descriptor with not found brick id" , func (t * testing.T ) {
47- app , err := ParseDescriptorFile (paths .New ("testdata/validator/not-found-brick-app.yaml" ))
48- require .NoError (t , err )
49- err = ValidateAppDescriptor (app , bricksIndex )
50- assert .Equal (t , "brick \" arduino:not_existing_brick\" not found" , err .Error ())
51- })
19+ testCases := []struct {
20+ name string
21+ filename string
22+ expectedErr * string
23+ }{
24+ {
25+ name : "valid app descriptor with no bricks" ,
26+ filename : "no-bricks-app.yaml" ,
27+ expectedErr : nil ,
28+ },
29+ {
30+ name : "valid app descriptor with empty list of bricks" ,
31+ filename : "empty-bricks-app.yaml" ,
32+ expectedErr : nil ,
33+ },
34+ {
35+ name : "invalid app descriptor with missing required variable" ,
36+ filename : "missing-required-app.yaml" ,
37+ expectedErr : f .Ptr ("variable \" ARDUINO_DEVICE_ID\" is required by brick \" arduino:arduino_cloud\" " ),
38+ },
39+ {
40+ name : "invalid app descriptor with a missing required variable among two" ,
41+ filename : "mixed-required-app.yaml" ,
42+ expectedErr : f .Ptr ("variable \" ARDUINO_SECRET\" is required by brick \" arduino:arduino_cloud\" " ),
43+ },
44+ {
45+ name : "invalid app descriptor with not found brick id" ,
46+ filename : "not-found-brick-app.yaml" ,
47+ expectedErr : f .Ptr ("brick \" arduino:not_existing_brick\" not found" ),
48+ },
49+ }
5250
51+ for _ , tc := range testCases {
52+ t .Run (tc .name , func (t * testing.T ) {
53+ app , err := ParseDescriptorFile (paths .New ("testdata/validator/" + tc .filename ))
54+ require .NoError (t , err )
55+
56+ err = ValidateBricks (app , bricksIndex )
57+
58+ if tc .expectedErr == nil {
59+ assert .NoError (t , err )
60+ } else {
61+ require .Error (t , err )
62+ assert .Equal (t , * tc .expectedErr , err .Error ())
63+ }
64+ })
65+ }
5366}
0 commit comments