Skip to content

Commit a8c8314

Browse files
committed
fix: update test cases for BrickCreate to improve clarity and logging
1 parent 18a0030 commit a8c8314

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

internal/orchestrator/bricks/bricks_test.go

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

1818
import (
19+
"fmt"
1920
"testing"
2021
"time"
2122

@@ -47,7 +48,7 @@ func TestBrickCreate(t *testing.T) {
4748
require.Equal(t, "variable \"NON_EXISTING_VARIABLE\" does not exist on brick \"arduino:arduino_cloud\"", err.Error())
4849
})
4950

50-
//TODO: allow a variable to have empty string
51+
//TODO: currently we do not accept an empty string as a valid value for a variable
5152
t.Run("fails if a required variable is set empty", func(t *testing.T) {
5253
req := BrickCreateUpdateRequest{ID: "arduino:arduino_cloud", Variables: map[string]string{
5354
"ARDUINO_DEVICE_ID": "",
@@ -59,8 +60,8 @@ func TestBrickCreate(t *testing.T) {
5960
})
6061

6162
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()
63+
tempApp, _ := copyToTempApp(t, paths.New("testdata/AppFromExample"))
64+
// defer cleanUp()
6465

6566
req := BrickCreateUpdateRequest{ID: "arduino:arduino_cloud", Variables: map[string]string{
6667
"ARDUINO_SECRET": "a-secret-a",
@@ -72,7 +73,7 @@ func TestBrickCreate(t *testing.T) {
7273
require.Nil(t, err)
7374
require.Len(t, after.Descriptor.Bricks, 1)
7475
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, "", after.Descriptor.Bricks[0].Variables["ARDUINO_DEVICE_ID"]) // <-- the DEVICE_ID is empty
7677
require.Equal(t, "a-secret-a", after.Descriptor.Bricks[0].Variables["ARDUINO_SECRET"])
7778
})
7879

@@ -119,7 +120,7 @@ func TestBrickCreate(t *testing.T) {
119120
}
120121

121122
func copyToTempApp(t *testing.T, srcApp *paths.Path) (tmpApp *paths.Path, cleanUp func()) {
122-
tmpAppPath := paths.New(srcApp.String() + time.Now().Format(time.RFC3339) + ".temp")
123+
tmpAppPath := paths.New(srcApp.String() + "-" + fmt.Sprint(time.Now().UnixMicro()) + ".temp")
123124
require.Nil(t, srcApp.CopyDirTo(tmpAppPath))
124125
return tmpAppPath, func() {
125126
require.Nil(t, tmpAppPath.RemoveAll())

0 commit comments

Comments
 (0)