-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload_test.go
More file actions
123 lines (106 loc) · 2.29 KB
/
Copy pathupload_test.go
File metadata and controls
123 lines (106 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package upload
import (
"context"
"encoding/binary"
"testing"
"time"
"github.com/metno/forti/fortiup/pkg/fortiblob"
"gocloud.dev/blob"
_ "gocloud.dev/blob/memblob"
)
func makeTestingClient() fortiblob.Client {
ctx := context.Background()
bucket, err := blob.OpenBucket(ctx, "mem://test")
if err != nil {
panic(err)
}
u := New(bucket)
area := "group_a"
version := 1
dsMeta := fortiblob.DatasetMeta{
Area: area,
Version: version,
}
if err := u.SetDatasetMeta(ctx, &dsMeta); err != nil {
panic(err)
}
gridid := "gridid1"
paMeta := fortiblob.MetaCollection{
Parameters: map[string]fortiblob.ParameterMeta{
"foo": {
Units: "uFoo",
Times: []time.Time{
time.Date(2020, 12, 24, 0, 0, 0, 0, time.UTC),
time.Date(2020, 12, 24, 1, 0, 0, 0, time.UTC),
time.Date(2020, 12, 24, 2, 0, 0, 0, time.UTC),
},
SliceFrom: 0,
},
"bar": {
Units: "uBar",
Times: nil,
SliceFrom: 3,
},
},
NumberOfPoints: 4,
}
if err := u.SetGridMeta(ctx, &paMeta, area, version, gridid); err != nil {
panic(err)
}
data, err := u.GetDataStream(ctx, area, version, gridid)
if err != nil {
panic(err)
}
defer data.Close()
dataValues := []int16{
01, 02, 03, 04,
11, 12, 13, 14,
21, 22, 23, 24,
31, 32, 33, 34,
}
if err := binary.Write(data, binary.LittleEndian, dataValues); err != nil {
panic(err)
}
lat, err := u.GetLatitudeStream(ctx, area, version, gridid)
if err != nil {
panic(err)
}
defer lat.Close()
latValues := []float32{
10, 10, 11, 11,
}
if err := binary.Write(lat, binary.LittleEndian, latValues); err != nil {
panic(err)
}
lon, err := u.GetLatitudeStream(ctx, area, version, gridid)
if err != nil {
panic(err)
}
defer lon.Close()
lonValues := []float32{
59, 60, 59, 60,
}
if err := binary.Write(lon, binary.LittleEndian, lonValues); err != nil {
panic(err)
}
return fortiblob.NewClientFromBucket(bucket)
}
func Test(t *testing.T) {
client := makeTestingClient()
defer client.Close()
ctx := context.Background()
latest, err := client.Latest(ctx)
if err != nil {
t.Fatal(err)
}
area := "group_a"
version := latest[area]
datasetMeta, err := client.GetMeta(ctx, area, version)
if err != nil {
t.Fatal(err)
}
_, err = client.GetGridInfo(ctx, datasetMeta)
if err != nil {
t.Fatal(err)
}
}