@@ -17,6 +17,7 @@ package bricks
1717
1818import (
1919 "testing"
20+ "time"
2021
2122 "github.com/arduino/go-paths-helper"
2223 "github.com/stretchr/testify/require"
@@ -46,6 +47,7 @@ func TestBrickCreateFromAppExample(t *testing.T) {
4647 require .Equal (t , "variable \" NON_EXISTING_VARIABLE\" does not exist on brick \" arduino:arduino_cloud\" " , err .Error ())
4748 })
4849
50+ //TODO: allow a variable to have empty string
4951 t .Run ("fails if a required variable is set empty" , func (t * testing.T ) {
5052 req := BrickCreateUpdateRequest {ID : "arduino:arduino_cloud" , Variables : map [string ]string {
5153 "ARDUINO_DEVICE_ID" : "" ,
@@ -56,13 +58,22 @@ func TestBrickCreateFromAppExample(t *testing.T) {
5658 require .Equal (t , "variable \" ARDUINO_DEVICE_ID\" cannot be empty" , err .Error ())
5759 })
5860
59- t .Run ("fails if a mandatory variable is not present in the request" , func (t * testing.T ) {
61+ t .Run ("log a warning if a mandatory variable is not present in the request" , func (t * testing.T ) {
62+ tempApp , cleanUp := copyToTempApp (t , paths .New ("testdata/AppFromExample" ))
63+ defer cleanUp ()
64+
6065 req := BrickCreateUpdateRequest {ID : "arduino:arduino_cloud" , Variables : map [string ]string {
6166 "ARDUINO_SECRET" : "a-secret-a" ,
6267 }}
63- err = brickService .BrickCreate (req , f .Must (app .Load ("testdata/AppFromExample" )))
64- require .Error (t , err )
65- require .Equal (t , "required variable \" ARDUINO_DEVICE_ID\" is mandatory" , err .Error ())
68+ err = brickService .BrickCreate (req , f .Must (app .Load (tempApp .String ())))
69+ require .Nil (t , err )
70+
71+ after , err := app .Load (tempApp .String ())
72+ require .Nil (t , err )
73+ require .Len (t , after .Descriptor .Bricks , 1 )
74+ require .Equal (t , "arduino:arduino_cloud" , after .Descriptor .Bricks [0 ].ID )
75+ require .Equal (t , "" , after .Descriptor .Bricks [0 ].Variables ["ARDUINO_DEVICE_ID" ]) // <-- the DEVICE_ID is set to empty
76+ require .Equal (t , "a-secret-a" , after .Descriptor .Bricks [0 ].Variables ["ARDUINO_SECRET" ])
6677 })
6778
6879 t .Run ("the brick is added if it does not exist in the app" , func (t * testing.T ) {
@@ -108,7 +119,7 @@ func TestBrickCreateFromAppExample(t *testing.T) {
108119}
109120
110121func copyToTempApp (t * testing.T , srcApp * paths.Path ) (tmpApp * paths.Path , cleanUp func ()) {
111- tmpAppPath := paths .New (srcApp .String () + ".temp" )
122+ tmpAppPath := paths .New (srcApp .String () + time . Now (). Format ( time . RFC3339 ) + ".temp" )
112123 require .Nil (t , srcApp .CopyDirTo (tmpAppPath ))
113124 return tmpAppPath , func () {
114125 require .Nil (t , tmpAppPath .RemoveAll ())
0 commit comments