@@ -66,43 +66,47 @@ func TestBrickCreate(t *testing.T) {
6666 })
6767
6868 t .Run ("the brick is added if it does not exist in the app" , func (t * testing.T ) {
69+ tempDummyApp := paths .New ("testdata/dummy-app.temp" )
70+ err := tempDummyApp .RemoveAll ()
71+ require .Nil (t , err )
72+ require .Nil (t , paths .New ("testdata/dummy-app" ).CopyDirTo (tempDummyApp ))
73+
6974 req := BrickCreateUpdateRequest {ID : "arduino:dbstorage_sqlstore" }
70- // TODO: find a better way to test if the brick has been added to the app.yaml
71- // Currently we only check that there is no error since the app.yaml is populated with the brick at every test execution.
72- err = brickService .BrickCreate (req , f .Must (app .Load ("testdata/dummy-app" )))
75+ err = brickService .BrickCreate (req , f .Must (app .Load (tempDummyApp .String ())))
7376 require .Nil (t , err )
77+ after , err := app .Load (tempDummyApp .String ())
78+ require .Nil (t , err )
79+ require .Len (t , after .Descriptor .Bricks , 2 )
80+ require .Equal (t , "arduino:dbstorage_sqlstore" , after .Descriptor .Bricks [1 ].ID )
7481 })
75- }
76-
77- func TestOverrideBrickVariablesOfApp (t * testing.T ) {
78- appWithOverride := paths .New ("testdata/my-app.override" )
79- err := appWithOverride .RemoveAll ()
80- require .Nil (t , err )
81-
82- err = paths .New ("testdata/my-app.source" ).CopyDirTo (appWithOverride )
83- require .Nil (t , err )
84- bricksIndex , err := bricksindex .GenerateBricksIndexFromFile (paths .New ("testdata" ))
85- require .Nil (t , err )
86- brickService := NewService (nil , bricksIndex , nil )
87-
88- deviceID := "this-is-a-device-id"
89- secret := "this-is-a-secret"
90-
91- req := BrickCreateUpdateRequest {
92- ID : "arduino:arduino_cloud" ,
93- Variables : map [string ]string {
94- "ARDUINO_DEVICE_ID" : deviceID ,
95- "ARDUINO_SECRET" : secret ,
96- },
97- }
98-
99- err = brickService .BrickCreate (req , f .Must (app .Load ("testdata/my-app.override" )))
100- require .Nil (t , err )
82+ t .Run ("the variables of a brick are updated" , func (t * testing.T ) {
83+ tempDummyApp := paths .New ("testdata/dummy-app.brick-override.temp" )
84+ err := tempDummyApp .RemoveAll ()
85+ require .Nil (t , err )
86+ err = paths .New ("testdata/dummy-app" ).CopyDirTo (tempDummyApp )
87+ require .Nil (t , err )
88+ bricksIndex , err := bricksindex .GenerateBricksIndexFromFile (paths .New ("testdata" ))
89+ require .Nil (t , err )
90+ brickService := NewService (nil , bricksIndex , nil )
91+
92+ deviceID := "this-is-a-device-id"
93+ secret := "this-is-a-secret"
94+ req := BrickCreateUpdateRequest {
95+ ID : "arduino:arduino_cloud" ,
96+ Variables : map [string ]string {
97+ "ARDUINO_DEVICE_ID" : deviceID ,
98+ "ARDUINO_SECRET" : secret ,
99+ },
100+ }
101+
102+ err = brickService .BrickCreate (req , f .Must (app .Load (tempDummyApp .String ())))
103+ require .Nil (t , err )
101104
102- after , err := app .Load ("testdata/my-app.override" )
103- require .Nil (t , err )
104- require .Len (t , after .Descriptor .Bricks , 1 )
105- require .Equal (t , "arduino:arduino_cloud" , after .Descriptor .Bricks [0 ].ID )
106- require .Equal (t , deviceID , after .Descriptor .Bricks [0 ].Variables ["ARDUINO_DEVICE_ID" ])
107- require .Equal (t , secret , after .Descriptor .Bricks [0 ].Variables ["ARDUINO_SECRET" ])
105+ after , err := app .Load (tempDummyApp .String ())
106+ require .Nil (t , err )
107+ require .Len (t , after .Descriptor .Bricks , 1 )
108+ require .Equal (t , "arduino:arduino_cloud" , after .Descriptor .Bricks [0 ].ID )
109+ require .Equal (t , deviceID , after .Descriptor .Bricks [0 ].Variables ["ARDUINO_DEVICE_ID" ])
110+ require .Equal (t , secret , after .Descriptor .Bricks [0 ].Variables ["ARDUINO_SECRET" ])
111+ })
108112}
0 commit comments