1616package bricks
1717
1818import (
19- "fmt"
20- "math/rand"
2119 "testing"
2220
2321 "github.com/stretchr/testify/require"
@@ -34,7 +32,7 @@ func TestBrickCreate(t *testing.T) {
3432 brickService := NewService (nil , bricksIndex , nil )
3533
3634 t .Run ("fails if brick id does not exist" , func (t * testing.T ) {
37- err = brickService .BrickCreate (BrickCreateUpdateRequest {ID : "not-existing-id" }, f .Must (app .Load ("./ testdata/my -app" )))
35+ err = brickService .BrickCreate (BrickCreateUpdateRequest {ID : "not-existing-id" }, f .Must (app .Load ("testdata/dummy -app" )))
3836 require .Error (t , err )
3937 require .Equal (t , "brick 'not-existing-id' not found" , err .Error ())
4038 })
@@ -43,7 +41,7 @@ func TestBrickCreate(t *testing.T) {
4341 req := BrickCreateUpdateRequest {ID : "arduino:arduino_cloud" , Variables : map [string ]string {
4442 "NON_EXISTING_VARIABLE" : "some-value" ,
4543 }}
46- err = brickService .BrickCreate (req , f .Must (app .Load ("./ testdata/my -app" )))
44+ err = brickService .BrickCreate (req , f .Must (app .Load ("testdata/dummy -app" )))
4745 require .Error (t , err )
4846 require .Equal (t , "variable 'NON_EXISTING_VARIABLE' does not exist on brick 'arduino:arduino_cloud'" , err .Error ())
4947 })
@@ -53,7 +51,7 @@ func TestBrickCreate(t *testing.T) {
5351 "ARDUINO_DEVICE_ID" : "" ,
5452 "ARDUINO_SECRET" : "a-secret-a" ,
5553 }}
56- err = brickService .BrickCreate (req , f .Must (app .Load ("./ testdata/my -app" )))
54+ err = brickService .BrickCreate (req , f .Must (app .Load ("testdata/dummy -app" )))
5755 require .Error (t , err )
5856 require .Equal (t , "variable 'ARDUINO_DEVICE_ID' cannot be empty" , err .Error ())
5957 })
@@ -62,7 +60,7 @@ func TestBrickCreate(t *testing.T) {
6260 req := BrickCreateUpdateRequest {ID : "arduino:arduino_cloud" , Variables : map [string ]string {
6361 "ARDUINO_SECRET" : "a-secret-a" ,
6462 }}
65- err = brickService .BrickCreate (req , f .Must (app .Load ("./ testdata/my -app" )))
63+ err = brickService .BrickCreate (req , f .Must (app .Load ("testdata/dummy -app" )))
6664 require .Error (t , err )
6765 require .Equal (t , "required variable 'ARDUINO_DEVICE_ID' is mandatory" , err .Error ())
6866 })
@@ -71,18 +69,23 @@ func TestBrickCreate(t *testing.T) {
7169 req := BrickCreateUpdateRequest {ID : "arduino:dbstorage_sqlstore" }
7270 // TODO: find a better way to test if the brick has been added to the app.yaml
7371 // Currently we only check that there is no error since the app.yaml is populated with the brick at every test execution.
74- err = brickService .BrickCreate (req , f .Must (app .Load ("./ testdata/my -app" )))
72+ err = brickService .BrickCreate (req , f .Must (app .Load ("testdata/dummy -app" )))
7573 require .Nil (t , err )
7674 })
7775}
7876
7977func TestOverrideBrickVariablesOfApp (t * testing.T ) {
78+ appWithOverride := paths .New ("testdata/my-app.override" )
79+ appWithOverride .RemoveAll ()
80+
81+ err := paths .New ("testdata/my-app.source" ).CopyDirTo (appWithOverride )
82+ require .Nil (t , err )
8083 bricksIndex , err := bricksindex .GenerateBricksIndexFromFile (paths .New ("testdata" ))
8184 require .Nil (t , err )
8285 brickService := NewService (nil , bricksIndex , nil )
8386
84- deviceID := fmt . Sprintf ( "my- device-id-%x" , rand . Int ())
85- secret := fmt . Sprintf ( "my-device-secret-%x" , rand . Int ())
87+ deviceID := "this-is-a- device-id"
88+ secret := "this-is-a-secret"
8689
8790 req := BrickCreateUpdateRequest {
8891 ID : "arduino:arduino_cloud" ,
@@ -92,10 +95,10 @@ func TestOverrideBrickVariablesOfApp(t *testing.T) {
9295 },
9396 }
9497
95- err = brickService .BrickCreate (req , f .Must (app .Load ("./ testdata/my-app" )))
98+ err = brickService .BrickCreate (req , f .Must (app .Load ("testdata/my-app.override " )))
9699 require .Nil (t , err )
97100
98- after , err := app .Load ("./ testdata/my-app" )
101+ after , err := app .Load ("testdata/my-app.override " )
99102 require .Nil (t , err )
100103 require .Len (t , after .Descriptor .Bricks , 1 )
101104 require .Equal (t , "arduino:arduino_cloud" , after .Descriptor .Bricks [0 ].ID )
0 commit comments