@@ -37,7 +37,19 @@ func TestUnmarshalProtocol(t *testing.T) {
37
37
expected : []Protocol {},
38
38
},
39
39
{
40
- raw : `{"webdav":{"sharedSecret":"secret","permissions":["read","write"],"url":"http://example.org"}}` ,
40
+ raw : `{"name":"foo","options":{ }}` ,
41
+ expected : []Protocol {},
42
+ },
43
+ {
44
+ raw : `{"name":"foo","options":{"unsupported":"value"}}` ,
45
+ err : `protocol options not supported: {"unsupported":"value"}` ,
46
+ },
47
+ {
48
+ raw : `{"not_existing":{}}` ,
49
+ err : "protocol not_existing not recognised" ,
50
+ },
51
+ {
52
+ raw : `{"name":"multi","options":{},"webdav":{"sharedSecret":"secret","permissions":["read","write"],"url":"http://example.org"}}` ,
41
53
expected : []Protocol {
42
54
& WebDAV {
43
55
SharedSecret : "secret" ,
@@ -47,15 +59,15 @@ func TestUnmarshalProtocol(t *testing.T) {
47
59
},
48
60
},
49
61
{
50
- raw : `{"webapp":{"uriTemplate":"http://example.org/{test}"}}` ,
62
+ raw : `{"name":"multi","options":{}," webapp":{"uriTemplate":"http://example.org/{test}"}}` ,
51
63
expected : []Protocol {
52
64
& Webapp {
53
65
URITemplate : "http://example.org/{test}" ,
54
66
},
55
67
},
56
68
},
57
69
{
58
- raw : `{"datatx":{"sharedSecret":"secret","srcUri":"http://example.org","size":10}}` ,
70
+ raw : `{"name":"multi","options":{}," datatx":{"sharedSecret":"secret","srcUri":"http://example.org","size":10}}` ,
59
71
expected : []Protocol {
60
72
& Datatx {
61
73
SharedSecret : "secret" ,
@@ -65,7 +77,7 @@ func TestUnmarshalProtocol(t *testing.T) {
65
77
},
66
78
},
67
79
{
68
- raw : `{"webdav":{"sharedSecret":"secret","permissions":["read","write"],"url":"http://example.org"},"webapp":{"uriTemplate":"http://example.org/{test}"},"datatx":{"sharedSecret":"secret","srcUri":"http://example.org","size":10}}` ,
80
+ raw : `{"name":"multi","options":{}," webdav":{"sharedSecret":"secret","permissions":["read","write"],"url":"http://example.org"},"webapp":{"uriTemplate":"http://example.org/{test}"},"datatx":{"sharedSecret":"secret","srcUri":"http://example.org","size":10}}` ,
69
81
expected : []Protocol {
70
82
& WebDAV {
71
83
SharedSecret : "secret" ,
@@ -82,10 +94,6 @@ func TestUnmarshalProtocol(t *testing.T) {
82
94
},
83
95
},
84
96
},
85
- {
86
- raw : `{"not_existing":{}}` ,
87
- err : "protocol not_existing not recognised" ,
88
- },
89
97
}
90
98
91
99
for _ , tt := range tests {
@@ -125,11 +133,12 @@ func protocolsEqual(p1, p2 Protocols) bool {
125
133
func TestMarshalProtocol (t * testing.T ) {
126
134
tests := []struct {
127
135
in Protocols
128
- expected map [string ]map [string ]any
136
+ expected map [string ]any
137
+ err string
129
138
}{
130
139
{
131
- in : []Protocol {},
132
- expected : map [ string ] map [ string ] any {} ,
140
+ in : []Protocol {},
141
+ err : "json: error calling MarshalJSON for type ocmd.Protocols: no protocol defined" ,
133
142
},
134
143
{
135
144
in : []Protocol {
@@ -139,8 +148,10 @@ func TestMarshalProtocol(t *testing.T) {
139
148
URL : "http://example.org" ,
140
149
},
141
150
},
142
- expected : map [string ]map [string ]any {
143
- "webdav" : {
151
+ expected : map [string ]any {
152
+ "name" : "multi" ,
153
+ "options" : map [string ]any {},
154
+ "webdav" : map [string ]any {
144
155
"sharedSecret" : "secret" ,
145
156
"permissions" : []any {"read" },
146
157
"url" : "http://example.org" ,
@@ -151,11 +162,15 @@ func TestMarshalProtocol(t *testing.T) {
151
162
in : []Protocol {
152
163
& Webapp {
153
164
URITemplate : "http://example.org" ,
165
+ ViewMode : "read" ,
154
166
},
155
167
},
156
- expected : map [string ]map [string ]any {
157
- "webapp" : {
168
+ expected : map [string ]any {
169
+ "name" : "multi" ,
170
+ "options" : map [string ]any {},
171
+ "webapp" : map [string ]any {
158
172
"uriTemplate" : "http://example.org" ,
173
+ "viewMode" : "read" ,
159
174
},
160
175
},
161
176
},
@@ -167,8 +182,10 @@ func TestMarshalProtocol(t *testing.T) {
167
182
Size : 10 ,
168
183
},
169
184
},
170
- expected : map [string ]map [string ]any {
171
- "datatx" : {
185
+ expected : map [string ]any {
186
+ "name" : "multi" ,
187
+ "options" : map [string ]any {},
188
+ "datatx" : map [string ]any {
172
189
"sharedSecret" : "secret" ,
173
190
"srcUri" : "http://example.org/source" ,
174
191
"size" : float64 (10 ),
@@ -184,23 +201,27 @@ func TestMarshalProtocol(t *testing.T) {
184
201
},
185
202
& Webapp {
186
203
URITemplate : "http://example.org" ,
204
+ ViewMode : "read" ,
187
205
},
188
206
& Datatx {
189
207
SharedSecret : "secret" ,
190
208
SourceURI : "http://example.org/source" ,
191
209
Size : 10 ,
192
210
},
193
211
},
194
- expected : map [string ]map [string ]any {
195
- "webdav" : {
212
+ expected : map [string ]any {
213
+ "name" : "multi" ,
214
+ "options" : map [string ]any {},
215
+ "webdav" : map [string ]any {
196
216
"sharedSecret" : "secret" ,
197
217
"permissions" : []any {"read" },
198
218
"url" : "http://example.org" ,
199
219
},
200
- "webapp" : {
220
+ "webapp" : map [ string ] any {
201
221
"uriTemplate" : "http://example.org" ,
222
+ "viewMode" : "read" ,
202
223
},
203
- "datatx" : {
224
+ "datatx" : map [ string ] any {
204
225
"sharedSecret" : "secret" ,
205
226
"srcUri" : "http://example.org/source" ,
206
227
"size" : float64 (10 ),
@@ -211,13 +232,13 @@ func TestMarshalProtocol(t *testing.T) {
211
232
212
233
for _ , tt := range tests {
213
234
d , err := json .Marshal (tt .in )
214
- if err != nil {
215
- t .Fatal ("not expected error" , err )
235
+ if err != nil && err . Error () != tt . err {
236
+ t .Fatalf ("not expected error. got=%+v expected=%+v " , err , tt . err )
216
237
}
217
238
218
- var got map [string ]map [ string ] any
239
+ var got map [string ]any
219
240
if err := json .Unmarshal (d , & got ); err != nil {
220
- t .Fatal ("not expected error" , err )
241
+ t .Fatalf ("not expected error %+v with input %+v " , err , tt . in )
221
242
}
222
243
223
244
if ! reflect .DeepEqual (tt .expected , got ) {
0 commit comments