@@ -10,6 +10,88 @@ import (
10
10
"github.com/stretchr/testify/require"
11
11
)
12
12
13
+ func TestItemExtendedMarshal (t * testing.T ) {
14
+ item := & stac.Item {
15
+ Version : "1.0.0" ,
16
+ Id : "item-id" ,
17
+ Geometry : map [string ]any {
18
+ "type" : "Point" ,
19
+ "coordinates" : []float64 {0 , 0 },
20
+ },
21
+ Properties : map [string ]any {
22
+ "test" : "value" ,
23
+ },
24
+ Links : []* stac.Link {
25
+ {Href : "https://example.com/stac/item-id" , Rel : "self" },
26
+ },
27
+ Assets : map [string ]* stac.Asset {
28
+ "image" : {
29
+ Title : "Image" ,
30
+ Href : "https://example.com/stac/item-id/image.tif" ,
31
+ Type : "image/tif" ,
32
+ Extensions : []stac.Extension {
33
+ & auth.Asset {
34
+ Refs : []string {"openid" },
35
+ },
36
+ },
37
+ },
38
+ },
39
+ Extensions : []stac.Extension {
40
+ & auth.Item {
41
+ Schemes : map [string ]* auth.Scheme {
42
+ "openid" : {
43
+ Type : "openIdConnect" ,
44
+ Description : "Test auth configuration" ,
45
+ OpenIdConnectUrl : "https://example.com/auth/.well-known/openid-configuration" ,
46
+ },
47
+ },
48
+ },
49
+ },
50
+ }
51
+
52
+ data , err := json .Marshal (item )
53
+ require .NoError (t , err )
54
+
55
+ expected := `{
56
+ "type": "Feature",
57
+ "stac_version": "1.0.0",
58
+ "id": "item-id",
59
+ "geometry": {
60
+ "type": "Point",
61
+ "coordinates": [0, 0]
62
+ },
63
+ "properties": {
64
+ "test": "value",
65
+ "auth:schemes": {
66
+ "openid": {
67
+ "type": "openIdConnect",
68
+ "description": "Test auth configuration",
69
+ "openIdConnectUrl": "https://example.com/auth/.well-known/openid-configuration"
70
+ }
71
+ }
72
+ },
73
+ "links": [
74
+ {
75
+ "rel": "self",
76
+ "href": "https://example.com/stac/item-id"
77
+ }
78
+ ],
79
+ "assets": {
80
+ "image": {
81
+ "title": "Image",
82
+ "href": "https://example.com/stac/item-id/image.tif",
83
+ "type": "image/tif",
84
+ "auth:refs": ["openid"]
85
+ }
86
+ },
87
+ "stac_extensions": [
88
+ "https://stac-extensions.github.io/authentication/v1.1.0/schema.json"
89
+ ]
90
+ }`
91
+
92
+ assert .JSONEq (t , expected , string (data ))
93
+ }
94
+
13
95
func TestCollectionExtendedMarshal (t * testing.T ) {
14
96
collection := & stac.Collection {
15
97
Version : "1.0.0" ,
@@ -150,6 +232,88 @@ func TestCollectionLinkExtendedMarshal(t *testing.T) {
150
232
assert .JSONEq (t , expected , string (data ))
151
233
}
152
234
235
+ func TestItemExtendedUnmarshal (t * testing.T ) {
236
+ data := []byte (`{
237
+ "type": "Feature",
238
+ "stac_version": "1.0.0",
239
+ "id": "item-id",
240
+ "geometry": {
241
+ "type": "Point",
242
+ "coordinates": [0, 0]
243
+ },
244
+ "properties": {
245
+ "test": "value",
246
+ "auth:schemes": {
247
+ "openid": {
248
+ "type": "openIdConnect",
249
+ "description": "Test auth configuration",
250
+ "openIdConnectUrl": "https://example.com/auth/.well-known/openid-configuration"
251
+ }
252
+ }
253
+ },
254
+ "links": [
255
+ {
256
+ "rel": "self",
257
+ "href": "https://example.com/stac/item-id"
258
+ }
259
+ ],
260
+ "assets": {
261
+ "image": {
262
+ "title": "Image",
263
+ "href": "https://example.com/stac/item-id/image.tif",
264
+ "type": "image/tif",
265
+ "auth:refs": ["openid"]
266
+ }
267
+ },
268
+ "stac_extensions": [
269
+ "https://stac-extensions.github.io/authentication/v1.1.0/schema.json"
270
+ ]
271
+ }` )
272
+
273
+ item := & stac.Item {}
274
+ require .NoError (t , json .Unmarshal (data , item ))
275
+
276
+ expected := & stac.Item {
277
+ Version : "1.0.0" ,
278
+ Id : "item-id" ,
279
+ Geometry : map [string ]any {
280
+ "type" : "Point" ,
281
+ "coordinates" : []any {float64 (0 ), float64 (0 )},
282
+ },
283
+ Properties : map [string ]any {
284
+ "test" : "value" ,
285
+ },
286
+ Links : []* stac.Link {
287
+ {Href : "https://example.com/stac/item-id" , Rel : "self" },
288
+ },
289
+ Assets : map [string ]* stac.Asset {
290
+ "image" : {
291
+ Title : "Image" ,
292
+ Href : "https://example.com/stac/item-id/image.tif" ,
293
+ Type : "image/tif" ,
294
+ Extensions : []stac.Extension {
295
+ & auth.Asset {
296
+ Refs : []string {"openid" },
297
+ },
298
+ },
299
+ },
300
+ },
301
+ Extensions : []stac.Extension {
302
+ & auth.Item {
303
+ Schemes : map [string ]* auth.Scheme {
304
+ "openid" : {
305
+ Type : "openIdConnect" ,
306
+ Description : "Test auth configuration" ,
307
+ OpenIdConnectUrl : "https://example.com/auth/.well-known/openid-configuration" ,
308
+ },
309
+ },
310
+ },
311
+ },
312
+ }
313
+
314
+ assert .Equal (t , expected , item )
315
+ }
316
+
153
317
func TestCollectionExtendedUnmarshal (t * testing.T ) {
154
318
data := []byte (`{
155
319
"type": "Collection",
0 commit comments