@@ -27,6 +27,17 @@ import (
27
27
"github.com/stretchr/testify/mock"
28
28
)
29
29
30
+ const (
31
+ // Real IDs will be UUIDs v4 like this: 9231a50b-8680-4489-a465-2b769fc310cb
32
+ // Here we use these text strings to improve test errors readability
33
+ switchyID = "switchy-id"
34
+ relayID = "relay-id"
35
+ blinkSpeedID = "blink_speed-id"
36
+
37
+ thingOverriddenID = "thing-overridden-id"
38
+ switchyOverriddenID = "switchy-overridden-id"
39
+ )
40
+
30
41
var (
31
42
dashboardTemplateTest = map [string ]interface {}{
32
43
"id" : "home-security-alarm-dashboard" ,
69
80
Widgets : []iotclient.Widget {
70
81
{Name : "Switch-name" , Height : 1 , HeightMobile : 2 , Width : 3 , WidthMobile : 4 ,
71
82
X : 5 , XMobile : 6 , Y : 7 , YMobile : 8 , Options : map [string ]interface {}{"showLabels" : true }, Type : "Switch" ,
72
- // variable id is set equal to the thing id by mockThingShow, in order to verify the thing override
73
- Variables : []string {"thing" },
83
+ Variables : []string {switchyID },
74
84
},
75
85
},
76
86
}
@@ -80,26 +90,21 @@ var (
80
90
Widgets : []iotclient.Widget {
81
91
{Name : "Switch-name" , Height : 1 , HeightMobile : 2 , Width : 3 , WidthMobile : 4 ,
82
92
X : 5 , XMobile : 6 , Y : 7 , YMobile : 8 , Options : map [string ]interface {}{"showLabels" : true }, Type : "Switch" ,
83
- // variable id is set equal to the thing id by mockThingShow, in order to verify the thing override
84
- Variables : []string {"overridden" },
93
+ Variables : []string {switchyOverriddenID },
85
94
},
86
95
},
87
96
}
88
97
89
98
dashboardTwoWidgets = & iotclient.Dashboardv2 {
90
99
Name : "dashboard-two-widgets" ,
91
- // in this test, the variable id is a concatenation of thing_id and variable_id
92
- // this depends on the mocked function getVariableID
93
100
Widgets : []iotclient.Widget {
94
101
{Name : "blink_speed" , Height : 7 , Width : 8 ,
95
102
X : 7 , Y : 5 , Options : map [string ]interface {}{"min" : float64 (0 ), "max" : float64 (5000 )}, Type : "Slider" ,
96
- // variable id is set equal to the thing id by mockThingShow, in order to verify the thing override
97
- Variables : []string {"remote-controlled-lights" },
103
+ Variables : []string {blinkSpeedID },
98
104
},
99
105
{Name : "relay_2" , Height : 5 , Width : 5 ,
100
106
X : 5 , Y : 0 , Options : map [string ]interface {}{"showLabels" : true }, Type : "Switch" ,
101
- // variable id is set equal to the thing id by mockThingShow, in order to verify the thing override
102
- Variables : []string {"remote-controlled-lights" },
107
+ Variables : []string {relayID },
103
108
},
104
109
},
105
110
}
@@ -143,17 +148,20 @@ func TestLoadTemplate(t *testing.T) {
143
148
func TestLoadDashboard (t * testing.T ) {
144
149
mockClient := & mocks.Client {}
145
150
mockThingShow := func (thingID string ) * iotclient.ArduinoThing {
146
- thing := & iotclient.ArduinoThing {
151
+ if thingID == thingOverriddenID {
152
+ return & iotclient.ArduinoThing {
153
+ Properties : []iotclient.ArduinoProperty {
154
+ {Id : switchyOverriddenID , Name : "switchy" },
155
+ },
156
+ }
157
+ }
158
+ return & iotclient.ArduinoThing {
147
159
Properties : []iotclient.ArduinoProperty {
148
- // variable id is set equal to the thing id in order to verify the thing override
149
- // dashboard-with-variable variable
150
- {Id : thingID , Name : "variable" },
151
- // dashboard-two-widgets variables
152
- {Id : thingID , Name : "relay_2" },
153
- {Id : thingID , Name : "blink_speed" },
160
+ {Id : switchyID , Name : "switchy" },
161
+ {Id : relayID , Name : "relay_2" },
162
+ {Id : blinkSpeedID , Name : "blink_speed" },
154
163
},
155
164
}
156
- return thing
157
165
}
158
166
mockClient .On ("ThingShow" , mock .AnythingOfType ("string" )).Return (mockThingShow , nil )
159
167
@@ -194,7 +202,7 @@ func TestLoadDashboard(t *testing.T) {
194
202
{
195
203
name : "dashboard with variable, thing is overridden" ,
196
204
file : "testdata/dashboard-with-variable.yaml" ,
197
- override : map [string ]string {"thing" : "overridden" },
205
+ override : map [string ]string {"thing" : thingOverriddenID },
198
206
want : dashboardVariableOverride ,
199
207
},
200
208
0 commit comments