@@ -134,7 +134,6 @@ func TestUdateBrick(t *testing.T) {
134134 require .Equal (t , "brick \" not-existing-id\" not found into the brick index" , err .Error ())
135135 })
136136
137- // TODO: if a brick is updated but it is corrunlty not in the app.yaml ? ithink we must add it to the app.yaml
138137 t .Run ("fails if brick is present into the index but not in the app " , func (t * testing.T ) {
139138 err = brickService .BrickUpdate (BrickCreateUpdateRequest {ID : "arduino:dbstorage_sqlstore" }, f .Must (app .Load ("testdata/dummy-app" )))
140139 require .Error (t , err )
@@ -150,6 +149,7 @@ func TestUdateBrick(t *testing.T) {
150149 require .Equal (t , "variable \" NON_EXISTING_VARIABLE\" does not exist on brick \" arduino:arduino_cloud\" " , err .Error ())
151150 })
152151
152+ // TODO: allow to set an empty "" varaible
153153 t .Run ("fails if a required variable is set empty" , func (t * testing.T ) {
154154 req := BrickCreateUpdateRequest {ID : "arduino:arduino_cloud" , Variables : map [string ]string {
155155 "ARDUINO_DEVICE_ID" : "" ,
@@ -174,8 +174,8 @@ func TestUdateBrick(t *testing.T) {
174174 require .Equal (t , "required variable \" ARDUINO_DEVICE_ID\" must be set" , err .Error ())
175175 })
176176
177- t .Run ("update the variables of a brick correctly" , func (t * testing.T ) {
178- tempDummyApp := paths .New ("testdata/dummy-app.brick-override. temp" )
177+ t .Run ("update a single variables of a brick correctly" , func (t * testing.T ) {
178+ tempDummyApp := paths .New ("testdata/dummy-app.temp" )
179179 require .Nil (t , tempDummyApp .RemoveAll ())
180180 require .Nil (t , paths .New ("testdata/dummy-app" ).CopyDirTo (tempDummyApp ))
181181 bricksIndex , err := bricksindex .GenerateBricksIndexFromFile (paths .New ("testdata" ))
@@ -203,6 +203,34 @@ func TestUdateBrick(t *testing.T) {
203203 require .Equal (t , secret , after .Descriptor .Bricks [0 ].Variables ["ARDUINO_SECRET" ])
204204 })
205205
206+ t .Run ("update a single variable correctly" , func (t * testing.T ) {
207+ tempDummyApp := paths .New ("testdata/dummy-app-for-update.temp" )
208+ require .Nil (t , tempDummyApp .RemoveAll ())
209+ require .Nil (t , paths .New ("testdata/dummy-app-for-update" ).CopyDirTo (tempDummyApp ))
210+ bricksIndex , err := bricksindex .GenerateBricksIndexFromFile (paths .New ("testdata" ))
211+ require .Nil (t , err )
212+ brickService := NewService (nil , bricksIndex , nil )
213+
214+ secret := "updated-the-secret"
215+ req := BrickCreateUpdateRequest {
216+ ID : "arduino:arduino_cloud" ,
217+ Variables : map [string ]string {
218+ // the ARDUINO_DEVICE_ID is already configured int the app.yaml
219+ "ARDUINO_SECRET" : secret ,
220+ },
221+ }
222+
223+ err = brickService .BrickUpdate (req , f .Must (app .Load (tempDummyApp .String ())))
224+ require .Nil (t , err )
225+
226+ after , err := app .Load (tempDummyApp .String ())
227+ require .Nil (t , err )
228+ require .Len (t , after .Descriptor .Bricks , 1 )
229+ require .Equal (t , "arduino:arduino_cloud" , after .Descriptor .Bricks [0 ].ID )
230+ require .Equal (t , "i-am-a-device-id" , after .Descriptor .Bricks [0 ].Variables ["ARDUINO_DEVICE_ID" ])
231+ require .Equal (t , secret , after .Descriptor .Bricks [0 ].Variables ["ARDUINO_SECRET" ])
232+ })
233+
206234}
207235
208236func TestGetBrickInstanceVariableDetails (t * testing.T ) {
0 commit comments