Skip to content

Commit 39b49e4

Browse files
committed
Improve uuid test
1 parent 45b3b42 commit 39b49e4

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

internal/template/load_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@ import (
2222

2323
"github.com/arduino/arduino-cloud-cli/internal/template/mocks"
2424
iotclient "github.com/arduino/iot-client-go"
25+
"github.com/gofrs/uuid"
2526
"github.com/google/go-cmp/cmp"
2627
"github.com/stretchr/testify/mock"
2728
)
2829

29-
const (
30-
uuidv4Length = 36
31-
)
32-
3330
var (
3431
dashboardTemplateTest = map[string]interface{}{
3532
"id": "home-security-alarm-dashboard",
@@ -144,7 +141,6 @@ func TestLoadTemplate(t *testing.T) {
144141
}
145142

146143
func TestLoadDashboard(t *testing.T) {
147-
148144
mockClient := &mocks.Client{}
149145
mockThingShow := func(thingID string) *iotclient.ArduinoThing {
150146
thing := &iotclient.ArduinoThing{
@@ -220,9 +216,11 @@ func TestLoadDashboard(t *testing.T) {
220216
for i := range got.Widgets {
221217
// check widget id generation
222218
id := got.Widgets[i].Id
223-
if len(id) != uuidv4Length {
224-
t.Errorf("Widget ID is wrong: = %s", id)
219+
_, err := uuid.FromString(id)
220+
if err != nil {
221+
t.Errorf("Widget ID is not a valid UUID: %s", id)
225222
}
223+
// Remove generated id to be able to compare the widget with the expected one
226224
got.Widgets[i].Id = ""
227225
}
228226

0 commit comments

Comments
 (0)