@@ -22,10 +22,12 @@ import (
22
22
23
23
"github.com/plgd-dev/device/v2/client"
24
24
"github.com/plgd-dev/device/v2/client/core"
25
+ "github.com/plgd-dev/device/v2/pkg/net/coap"
25
26
"github.com/plgd-dev/device/v2/schema/configuration"
26
27
"github.com/plgd-dev/device/v2/schema/device"
27
28
"github.com/plgd-dev/device/v2/schema/interfaces"
28
29
"github.com/plgd-dev/device/v2/test"
30
+ "github.com/plgd-dev/go-coap/v3/message/codes"
29
31
"github.com/stretchr/testify/require"
30
32
)
31
33
@@ -40,7 +42,7 @@ func TestClientUpdateResource(t *testing.T) {
40
42
tests := []struct {
41
43
name string
42
44
args args
43
- want interface {}
45
+ want coap. DetailedResponse [ interface {}]
44
46
wantErr bool
45
47
}{
46
48
{
@@ -53,8 +55,11 @@ func TestClientUpdateResource(t *testing.T) {
53
55
},
54
56
opts : []client.UpdateOption {client .WithDiscoveryConfiguration (core .DefaultDiscoveryConfiguration ())},
55
57
},
56
- want : map [interface {}]interface {}{
57
- "n" : t .Name () + "-valid" ,
58
+ want : coap.DetailedResponse [interface {}]{
59
+ Code : codes .Changed ,
60
+ Body : map [interface {}]interface {}{
61
+ "n" : t .Name () + "-valid" ,
62
+ },
58
63
},
59
64
},
60
65
{
@@ -67,8 +72,11 @@ func TestClientUpdateResource(t *testing.T) {
67
72
},
68
73
opts : []client.UpdateOption {client .WithInterface (interfaces .OC_IF_BASELINE )},
69
74
},
70
- want : map [interface {}]interface {}{
71
- "n" : t .Name () + "-valid with interface" ,
75
+ want : coap.DetailedResponse [interface {}]{
76
+ Code : codes .Changed ,
77
+ Body : map [interface {}]interface {}{
78
+ "n" : t .Name () + "-valid with interface" ,
79
+ },
72
80
},
73
81
},
74
82
{
@@ -80,8 +88,11 @@ func TestClientUpdateResource(t *testing.T) {
80
88
"n" : test .DevsimName ,
81
89
},
82
90
},
83
- want : map [interface {}]interface {}{
84
- "n" : test .DevsimName ,
91
+ want : coap.DetailedResponse [interface {}]{
92
+ Code : codes .Changed ,
93
+ Body : map [interface {}]interface {}{
94
+ "n" : test .DevsimName ,
95
+ },
85
96
},
86
97
},
87
98
{
@@ -120,7 +131,7 @@ func TestClientUpdateResource(t *testing.T) {
120
131
121
132
for _ , tt := range tests {
122
133
t .Run (tt .name , func (t * testing.T ) {
123
- var got interface {}
134
+ var got coap. DetailedResponse [ interface {}]
124
135
err = c .UpdateResource (ctx , tt .args .deviceID , tt .args .href , tt .args .data , & got , tt .args .opts ... )
125
136
if tt .wantErr {
126
137
require .Error (t , err )
@@ -143,7 +154,7 @@ func TestClientUpdateResourceInRFOTM(t *testing.T) {
143
154
tests := []struct {
144
155
name string
145
156
args args
146
- want interface {}
157
+ want coap. DetailedResponse [ interface {}]
147
158
wantErr bool
148
159
}{
149
160
{
@@ -156,10 +167,13 @@ func TestClientUpdateResourceInRFOTM(t *testing.T) {
156
167
},
157
168
opts : []client.UpdateOption {client .WithDiscoveryConfiguration (core .DefaultDiscoveryConfiguration ())},
158
169
},
159
- want : map [interface {}]interface {}{
160
- "name" : "Light" ,
161
- "power" : uint64 (0 ),
162
- "state" : true ,
170
+ want : coap.DetailedResponse [interface {}]{
171
+ Code : codes .Content ,
172
+ Body : map [interface {}]interface {}{
173
+ "name" : "Light" ,
174
+ "power" : uint64 (0 ),
175
+ "state" : true ,
176
+ },
163
177
},
164
178
},
165
179
{
@@ -172,10 +186,13 @@ func TestClientUpdateResourceInRFOTM(t *testing.T) {
172
186
},
173
187
opts : []client.UpdateOption {client .WithInterface (interfaces .OC_IF_BASELINE )},
174
188
},
175
- want : map [interface {}]interface {}{
176
- "name" : "Light" ,
177
- "power" : uint64 (1 ),
178
- "state" : true ,
189
+ want : coap.DetailedResponse [interface {}]{
190
+ Code : codes .Content ,
191
+ Body : map [interface {}]interface {}{
192
+ "name" : "Light" ,
193
+ "power" : uint64 (1 ),
194
+ "state" : true ,
195
+ },
179
196
},
180
197
},
181
198
{
@@ -188,10 +205,13 @@ func TestClientUpdateResourceInRFOTM(t *testing.T) {
188
205
"power" : uint64 (0 ),
189
206
},
190
207
},
191
- want : map [interface {}]interface {}{
192
- "name" : "Light" ,
193
- "power" : uint64 (0 ),
194
- "state" : false ,
208
+ want : coap.DetailedResponse [interface {}]{
209
+ Code : codes .Content ,
210
+ Body : map [interface {}]interface {}{
211
+ "name" : "Light" ,
212
+ "power" : uint64 (0 ),
213
+ "state" : false ,
214
+ },
195
215
},
196
216
},
197
217
{
@@ -235,9 +255,10 @@ func TestClientUpdateResourceInRFOTM(t *testing.T) {
235
255
return
236
256
}
237
257
require .NoError (t , err )
238
- var got interface {}
258
+ var got coap. DetailedResponse [ interface {}]
239
259
err = c .GetResource (ctx , tt .args .deviceID , tt .args .href , & got )
240
260
require .NoError (t , err )
261
+ got .ETag = nil
241
262
require .Equal (t , tt .want , got )
242
263
})
243
264
}
0 commit comments