Skip to content

Commit c579998

Browse files
committed
feat(tests): update BrickCreate tests and add dummy app configurations
1 parent d1e01fe commit c579998

File tree

8 files changed

+34
-11
lines changed

8 files changed

+34
-11
lines changed

internal/orchestrator/bricks/bricks_test.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
package bricks
1717

1818
import (
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

7977
func 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)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
my-app.override/
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: Copy of Blinking LED from Arduino Cloud
2+
description: Control the LED from the Arduino IoT Cloud using RPC calls
3+
ports: []
4+
bricks:
5+
- arduino:arduino_cloud:
6+
variables:
7+
ARDUINO_DEVICE_ID: this-is-a-device-id
8+
ARDUINO_SECRET: this-is-a-secret
9+
icon: ☁️
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def main():
2+
# empty file
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: Copy of Blinking LED from Arduino Cloud
2+
description: Control the LED from the Arduino IoT Cloud using RPC calls
3+
ports: []
4+
bricks:
5+
- arduino:arduino_cloud:
6+
icon: ☁️
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def main():
2+
# empty file

0 commit comments

Comments
 (0)