Skip to content

Commit 675eb05

Browse files
committed
Update model test updates and additions
1 parent bdc6838 commit 675eb05

17 files changed

+2587
-60
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package model_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/enbility/eebus-go/spine/model"
7+
"github.com/enbility/eebus-go/util"
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestDeviceConfigurationKeyValueListDataType_Update(t *testing.T) {
12+
sut := model.DeviceConfigurationKeyValueListDataType{
13+
DeviceConfigurationKeyValueData: []model.DeviceConfigurationKeyValueDataType{
14+
{
15+
KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(0)),
16+
Value: &model.DeviceConfigurationKeyValueValueType{
17+
Boolean: util.Ptr(true),
18+
},
19+
},
20+
{
21+
KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(1)),
22+
Value: &model.DeviceConfigurationKeyValueValueType{
23+
Boolean: util.Ptr(true),
24+
},
25+
},
26+
},
27+
}
28+
29+
newData := model.DeviceConfigurationKeyValueListDataType{
30+
DeviceConfigurationKeyValueData: []model.DeviceConfigurationKeyValueDataType{
31+
{
32+
KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(1)),
33+
Value: &model.DeviceConfigurationKeyValueValueType{
34+
Boolean: util.Ptr(false),
35+
},
36+
},
37+
},
38+
}
39+
40+
// Act
41+
sut.UpdateList(&newData, model.NewFilterTypePartial(), nil)
42+
43+
data := sut.DeviceConfigurationKeyValueData
44+
// check the non changing items
45+
assert.Equal(t, 2, len(data))
46+
item1 := data[0]
47+
assert.Equal(t, 0, int(*item1.KeyId))
48+
assert.Equal(t, true, *item1.Value.Boolean)
49+
// check properties of updated item
50+
item2 := data[1]
51+
assert.Equal(t, 1, int(*item2.KeyId))
52+
assert.Equal(t, false, *item2.Value.Boolean)
53+
}
54+
55+
func TestDeviceConfigurationKeyValueDescriptionListDataType_Update(t *testing.T) {
56+
sut := model.DeviceConfigurationKeyValueDescriptionListDataType{
57+
DeviceConfigurationKeyValueDescriptionData: []model.DeviceConfigurationKeyValueDescriptionDataType{
58+
{
59+
KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(0)),
60+
ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeBoolean),
61+
},
62+
{
63+
KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(1)),
64+
ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeBoolean),
65+
},
66+
},
67+
}
68+
69+
newData := model.DeviceConfigurationKeyValueDescriptionListDataType{
70+
DeviceConfigurationKeyValueDescriptionData: []model.DeviceConfigurationKeyValueDescriptionDataType{
71+
{
72+
KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(1)),
73+
ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeString),
74+
},
75+
},
76+
}
77+
78+
// Act
79+
sut.UpdateList(&newData, model.NewFilterTypePartial(), nil)
80+
81+
data := sut.DeviceConfigurationKeyValueDescriptionData
82+
// check the non changing items
83+
assert.Equal(t, 2, len(data))
84+
item1 := data[0]
85+
assert.Equal(t, 0, int(*item1.KeyId))
86+
assert.Equal(t, model.DeviceConfigurationKeyValueTypeTypeBoolean, *item1.ValueType)
87+
// check properties of updated item
88+
item2 := data[1]
89+
assert.Equal(t, 1, int(*item2.KeyId))
90+
assert.Equal(t, model.DeviceConfigurationKeyValueTypeTypeString, *item2.ValueType)
91+
}
92+
93+
func TestDeviceConfigurationKeyValueConstraintsListDataType_Update(t *testing.T) {
94+
sut := model.DeviceConfigurationKeyValueConstraintsListDataType{
95+
DeviceConfigurationKeyValueConstraintsData: []model.DeviceConfigurationKeyValueConstraintsDataType{
96+
{
97+
KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(0)),
98+
ValueStepSize: &model.DeviceConfigurationKeyValueValueType{
99+
Boolean: util.Ptr(true),
100+
},
101+
},
102+
{
103+
KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(1)),
104+
ValueStepSize: &model.DeviceConfigurationKeyValueValueType{
105+
Boolean: util.Ptr(true),
106+
},
107+
},
108+
},
109+
}
110+
111+
newData := model.DeviceConfigurationKeyValueConstraintsListDataType{
112+
DeviceConfigurationKeyValueConstraintsData: []model.DeviceConfigurationKeyValueConstraintsDataType{
113+
{
114+
KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(1)),
115+
ValueStepSize: &model.DeviceConfigurationKeyValueValueType{
116+
Boolean: util.Ptr(false),
117+
},
118+
},
119+
},
120+
}
121+
122+
// Act
123+
sut.UpdateList(&newData, model.NewFilterTypePartial(), nil)
124+
125+
data := sut.DeviceConfigurationKeyValueConstraintsData
126+
// check the non changing items
127+
assert.Equal(t, 2, len(data))
128+
item1 := data[0]
129+
assert.Equal(t, 0, int(*item1.KeyId))
130+
assert.Equal(t, true, *item1.ValueStepSize.Boolean)
131+
// check properties of updated item
132+
item2 := data[1]
133+
assert.Equal(t, 1, int(*item2.KeyId))
134+
assert.Equal(t, false, *item2.ValueStepSize.Boolean)
135+
}

0 commit comments

Comments
 (0)