@@ -18,58 +18,52 @@ func TestValidateAppDescriptorBricks(t *testing.T) {
1818 require .NotNil (t , bricksIndex )
1919
2020 testCases := []struct {
21- name string
22- filename string
23- expectedErrors [] error // Now expecting a slice of error messages
21+ name string
22+ filename string
23+ expectedError error
2424 }{
2525 {
26- name : "valid with all required filled" ,
27- filename : "all-required-app.yaml" ,
28- expectedErrors : nil ,
26+ name : "valid with all required filled" ,
27+ filename : "all-required-app.yaml" ,
28+ expectedError : nil ,
2929 },
3030 {
31- name : "valid with missing bricks" ,
32- filename : "no-bricks-app.yaml" ,
33- expectedErrors : nil ,
31+ name : "valid with missing bricks" ,
32+ filename : "no-bricks-app.yaml" ,
33+ expectedError : nil ,
3434 },
3535 {
36- name : "valid with empty list of bricks" ,
37- filename : "empty-bricks-app.yaml" ,
38- expectedErrors : nil ,
36+ name : "valid with empty list of bricks" ,
37+ filename : "empty-bricks-app.yaml" ,
38+ expectedError : nil ,
3939 },
4040 {
41- name : "valid if required variable is empty string" ,
42- filename : "empty-required-app.yaml" ,
43- expectedErrors : nil ,
41+ name : "valid if required variable is empty string" ,
42+ filename : "empty-required-app.yaml" ,
43+ expectedError : nil ,
4444 },
4545 {
4646 name : "invalid if required variable is omitted" ,
4747 filename : "omitted-required-app.yaml" ,
48- expectedErrors : [] error {
48+ expectedError : errors . Join (
4949 errors .New ("variable \" ARDUINO_DEVICE_ID\" is required by brick \" arduino:arduino_cloud\" " ),
5050 errors .New ("variable \" ARDUINO_SECRET\" is required by brick \" arduino:arduino_cloud\" " ),
51- } ,
51+ ) ,
5252 },
5353 {
54- name : "invalid if a required variable among two is omitted" ,
55- filename : "omitted-mixed-required-app.yaml" ,
56- expectedErrors : []error {
57- errors .New ("variable \" ARDUINO_SECRET\" is required by brick \" arduino:arduino_cloud\" " ),
58- },
54+ name : "invalid if a required variable among two is omitted" ,
55+ filename : "omitted-mixed-required-app.yaml" ,
56+ expectedError : errors .New ("variable \" ARDUINO_SECRET\" is required by brick \" arduino:arduino_cloud\" " ),
5957 },
6058 {
61- name : "invalid if brick id not found" ,
62- filename : "not-found-brick-app.yaml" ,
63- expectedErrors : []error {
64- errors .New ("brick \" arduino:not_existing_brick\" not found" ),
65- },
59+ name : "invalid if brick id not found" ,
60+ filename : "not-found-brick-app.yaml" ,
61+ expectedError : errors .New ("brick \" arduino:not_existing_brick\" not found" ),
6662 },
6763 {
68- name : "invalid if variable does not exist in the brick" ,
69- filename : "not-found-variable-app.yaml" ,
70- expectedErrors : []error {
71- errors .New ("variable \" NOT_EXISTING_VARIABLE\" does not exist on brick \" arduino:arduino_cloud\" " ),
72- },
64+ name : "invalid if variable does not exist in the brick" ,
65+ filename : "not-found-variable-app.yaml" ,
66+ expectedError : errors .New ("variable \" NOT_EXISTING_VARIABLE\" does not exist on brick \" arduino:arduino_cloud\" " ),
7367 },
7468 }
7569
@@ -78,13 +72,12 @@ func TestValidateAppDescriptorBricks(t *testing.T) {
7872 appDescriptor , err := ParseDescriptorFile (paths .New ("testdata/validator/" + tc .filename ))
7973 require .NoError (t , err )
8074
81- errs := appDescriptor .ValidateBricks (bricksIndex )
82- if tc .expectedErrors == nil {
83- require .Nil (t , errs )
84- assert .Empty (t , errs , "Expected no validation errors" )
75+ err = appDescriptor .ValidateBricks (bricksIndex )
76+ if tc .expectedError == nil {
77+ assert .NoError (t , err , "Expected no validation errors" )
8578 } else {
86- require .Len (t , errs , len ( tc . expectedErrors ), "Expected %d errors but got %d" , len ( tc . expectedErrors ), len ( errs ) )
87- require . Exactly (t , tc .expectedErrors , errs )
79+ require .Error (t , err , "Expected validation error" )
80+ assert . Equal (t , tc .expectedError . Error (), err . Error (), "Error message should match" )
8881 }
8982 })
9083 }
0 commit comments