Skip to content

Commit 3163093

Browse files
committed
Add test for unmarshalling a list of items
1 parent 7a78941 commit 3163093

File tree

2 files changed

+255
-0
lines changed

2 files changed

+255
-0
lines changed

item_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package stac_test
22

33
import (
44
"encoding/json"
5+
"os"
56
"testing"
67

78
"github.com/planetlabs/go-stac"
9+
"github.com/planetlabs/go-stac/extensions/eo/v1"
810
"github.com/stretchr/testify/assert"
911
"github.com/stretchr/testify/require"
1012
)
@@ -157,3 +159,31 @@ func TestGeometryUnmarshal(t *testing.T) {
157159
require.True(t, ok)
158160
assert.NotNil(t, g.data)
159161
}
162+
163+
func getExtension(item *stac.Item, uri string) stac.Extension {
164+
for _, extension := range item.Extensions {
165+
if extension.URI() == uri {
166+
return extension
167+
}
168+
}
169+
return nil
170+
}
171+
172+
func TestItemListUnmarshal(t *testing.T) {
173+
data, err := os.ReadFile("testdata/items.json")
174+
require.NoError(t, err)
175+
176+
itemList := &stac.ItemsList{}
177+
require.NoError(t, json.Unmarshal([]byte(data), itemList))
178+
179+
require.Len(t, itemList.Items, 2)
180+
first := itemList.Items[0]
181+
182+
eoExtension := getExtension(first, "https://stac-extensions.github.io/eo/v1.1.0/schema.json")
183+
require.NotNil(t, eoExtension)
184+
eo, ok := eoExtension.(*eo.Item)
185+
require.True(t, ok)
186+
187+
require.NotNil(t, eo.CloudCover)
188+
assert.Equal(t, float64(50), *eo.CloudCover)
189+
}

testdata/items.json

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [
4+
{
5+
"assets": {
6+
"thumbnail": {
7+
"auth:refs": [
8+
"openid"
9+
],
10+
"href": "https://tiles.planet.com/data/v1/item-types/PSScene/items/20250804_153448_85_2533/thumb?width=512",
11+
"roles": [
12+
"overview"
13+
],
14+
"title": "Image Thumbnail",
15+
"type": "image/png"
16+
}
17+
},
18+
"bbox": [
19+
-73.258517045974,
20+
-16.69413428340269,
21+
-72.88920081160497,
22+
-16.44078244605111
23+
],
24+
"collection": "PSScene",
25+
"geometry": {
26+
"coordinates": [
27+
[
28+
[
29+
-73.21921515523202,
30+
-16.44078244605111
31+
],
32+
[
33+
-72.88920081160497,
34+
-16.50383386770677
35+
],
36+
[
37+
-72.92830966824664,
38+
-16.69413428340269
39+
],
40+
[
41+
-73.258517045974,
42+
-16.630494685555924
43+
],
44+
[
45+
-73.21921515523202,
46+
-16.44078244605111
47+
]
48+
]
49+
],
50+
"type": "Polygon"
51+
},
52+
"id": "20250804_153448_85_2533",
53+
"links": [
54+
{
55+
"auth:refs": [
56+
"openid"
57+
],
58+
"href": "https://api.planet.com/x/data/collections/PSScene/items/20250804_153448_85_2533",
59+
"rel": "self",
60+
"title": "Item Details",
61+
"type": "application/geo+json"
62+
}
63+
],
64+
"properties": {
65+
"auth:schemes": {
66+
"openid": {
67+
"type": "openIdConnect",
68+
"description": "Planet OpenID Provider",
69+
"openIdConnectUrl": "https://login.planet.com/.well-known/openid-configuration"
70+
}
71+
},
72+
"constellation": "planetscope",
73+
"created": "2025-08-04T16:53:02Z",
74+
"datetime": "2025-08-04T15:34:48.858029Z",
75+
"eo:cloud_cover": 50,
76+
"eo:snow_cover": 0,
77+
"gsd": 4,
78+
"instruments": [
79+
"PSB.SD"
80+
],
81+
"pl:clear_percent": 44,
82+
"pl:ground_control": false,
83+
"pl:item_type": "PSScene",
84+
"pl:pixel_resolution": 3,
85+
"pl:publishing_stage": "preview",
86+
"pl:quality_category": "test",
87+
"pl:strip_id": "8234808",
88+
"platform": "2533",
89+
"updated": "2025-08-04T16:53:02Z",
90+
"view:azimuth": 280.3,
91+
"view:off_nadir": 2.1,
92+
"view:sun_azimuth": 32.7,
93+
"view:sun_elevation": 50.5
94+
},
95+
"stac_extensions": [
96+
"https://planetlabs.github.io/stac-extension/v1.0.0-beta.3/schema.json",
97+
"https://stac-extensions.github.io/authentication/v1.1.0/schema.json",
98+
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
99+
"https://stac-extensions.github.io/view/v1.0.0/schema.json"
100+
],
101+
"stac_version": "1.0.0",
102+
"type": "Feature"
103+
},
104+
{
105+
"assets": {
106+
"thumbnail": {
107+
"auth:refs": [
108+
"openid"
109+
],
110+
"href": "https://tiles.planet.com/data/v1/item-types/PSScene/items/20250804_153446_72_2533/thumb?width=512",
111+
"roles": [
112+
"overview"
113+
],
114+
"title": "Image Thumbnail",
115+
"type": "image/png"
116+
}
117+
},
118+
"bbox": [
119+
-73.23124120340088,
120+
-16.559480128427975,
121+
-72.86221827276259,
122+
-16.306158115768216
123+
],
124+
"collection": "PSScene",
125+
"geometry": {
126+
"coordinates": [
127+
[
128+
[
129+
-73.19197912148246,
130+
-16.306158115768216
131+
],
132+
[
133+
-72.86221827276259,
134+
-16.369192673645173
135+
],
136+
[
137+
-72.90128981124934,
138+
-16.559480128427975
139+
],
140+
[
141+
-73.23124120340088,
142+
-16.495859859350162
143+
],
144+
[
145+
-73.19197912148246,
146+
-16.306158115768216
147+
]
148+
]
149+
],
150+
"type": "Polygon"
151+
},
152+
"id": "20250804_153446_72_2533",
153+
"links": [
154+
{
155+
"auth:refs": [
156+
"openid"
157+
],
158+
"href": "https://api.planet.com/x/data/collections/PSScene/items/20250804_153446_72_2533",
159+
"rel": "self",
160+
"title": "Item Details",
161+
"type": "application/geo+json"
162+
}
163+
],
164+
"properties": {
165+
"auth:schemes": {
166+
"openid": {
167+
"type": "openIdConnect",
168+
"description": "Planet OpenID Provider",
169+
"openIdConnectUrl": "https://login.planet.com/.well-known/openid-configuration"
170+
}
171+
},
172+
"constellation": "planetscope",
173+
"created": "2025-08-04T16:48:04Z",
174+
"datetime": "2025-08-04T15:34:46.722464Z",
175+
"eo:cloud_cover": 19,
176+
"eo:snow_cover": 0,
177+
"gsd": 4,
178+
"instruments": [
179+
"PSB.SD"
180+
],
181+
"pl:clear_percent": 78,
182+
"pl:ground_control": false,
183+
"pl:item_type": "PSScene",
184+
"pl:pixel_resolution": 3,
185+
"pl:publishing_stage": "preview",
186+
"pl:quality_category": "test",
187+
"pl:strip_id": "8234808",
188+
"platform": "2533",
189+
"updated": "2025-08-04T16:48:04Z",
190+
"view:azimuth": 280.3,
191+
"view:off_nadir": 2.1,
192+
"view:sun_azimuth": 32.8,
193+
"view:sun_elevation": 50.6
194+
},
195+
"stac_extensions": [
196+
"https://planetlabs.github.io/stac-extension/v1.0.0-beta.3/schema.json",
197+
"https://stac-extensions.github.io/authentication/v1.1.0/schema.json",
198+
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
199+
"https://stac-extensions.github.io/view/v1.0.0/schema.json"
200+
],
201+
"stac_version": "1.0.0",
202+
"type": "Feature"
203+
}
204+
],
205+
"links": [
206+
{
207+
"href": "https://api.planet.com/x/data/",
208+
"rel": "root",
209+
"title": "Root Catalog",
210+
"type": "application/json"
211+
},
212+
{
213+
"href": "https://api.planet.com/x/data/collections/PSScene/items?limit=2",
214+
"rel": "self",
215+
"title": "Items List",
216+
"type": "application/geo+json"
217+
},
218+
{
219+
"href": "https://api.planet.com/x/data/collections/PSScene",
220+
"rel": "collection",
221+
"title": "Collection Details",
222+
"type": "application/json"
223+
}
224+
]
225+
}

0 commit comments

Comments
 (0)