-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
189 lines (151 loc) · 5.44 KB
/
config_test.go
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
RexRegistry Dataset Delivery
Copyright (C) 2019 Prometheus Research, LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package rexdeliverdataset_test
import (
"os"
"runtime"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
rdd "github.com/prometheusresearch/rex_deliver_dataset"
)
var _ = Describe("Config", func() {
Describe("NewConfiguration", func() {
It("Works", func() {
cfg := rdd.NewConfiguration()
Expect(cfg.ExecutionTime).To(Not(BeNil()))
Expect(cfg.Storage).To(Not(BeNil()))
})
})
Describe("Validate", func() {
It("Checks Basic Storage Props", func() {
cfg := rdd.NewConfiguration()
cfg.DatasetType = "omop:5.2:csv"
err := cfg.Validate()
Expect(err).To(MatchError("storage requires kind property"))
cfg.Storage["kind"] = "gs"
err = cfg.Validate()
Expect(err).To(MatchError("storage requires container property"))
cfg.Storage["container"] = "test"
cfg.Storage["credentials_json"] = "/some/file.json"
err = cfg.Validate()
Expect(err).To(Succeed())
})
It("Checks S3 Storage", func() {
cfg := rdd.NewConfiguration()
cfg.DatasetType = "omop:5.2:csv"
cfg.Storage["kind"] = "s3"
cfg.Storage["container"] = "test"
err := cfg.Validate()
Expect(err).To(MatchError("storage requires access_key property when kind=s3"))
cfg.Storage["access_key"] = "foo"
err = cfg.Validate()
Expect(err).To(MatchError("storage requires secret_key property when kind=s3"))
cfg.Storage["secret_key"] = "bar"
err = cfg.Validate()
Expect(err).To(MatchError("storage requires region property when kind=s3"))
cfg.Storage["region"] = "baz"
err = cfg.Validate()
Expect(err).To(Succeed())
})
It("Checks GCS Storage", func() {
cfg := rdd.NewConfiguration()
cfg.DatasetType = "omop:5.2:csv"
cfg.Storage["kind"] = "gs"
cfg.Storage["container"] = "test"
err := cfg.Validate()
Expect(err).To(MatchError("storage requires credentials_json property when kind=gs"))
cfg.Storage["credentials_json"] = "foo"
err = cfg.Validate()
Expect(err).To(Succeed())
})
It("Checks Local Storage", func() {
cfg := rdd.NewConfiguration()
cfg.DatasetType = "omop:5.2:csv"
cfg.Storage["kind"] = "local"
cfg.Storage["container"] = "test"
err := cfg.Validate()
if runtime.GOOS == "windows" {
Expect(err).To(MatchError("storage.kind cannot be local on Windows systems"))
} else {
Expect(err).To(MatchError("storage requires path property when kind=local"))
cfg.Storage["path"] = "/foo"
err = cfg.Validate()
Expect(err).To(Succeed())
}
})
It("Handles Unknown Kind", func() {
cfg := rdd.NewConfiguration()
cfg.DatasetType = "omop:5.2:csv"
cfg.Storage["kind"] = "foo"
cfg.Storage["container"] = "test"
err := cfg.Validate()
Expect(err).To(MatchError("storage.kind must be one of: gs, local, s3"))
})
It("Handles Bad Path", func() {
cfg := rdd.NewConfiguration()
cfg.DatasetType = "omop:5.2:csv"
cfg.Storage["kind"] = "gs"
cfg.Storage["container"] = "test"
cfg.Storage["credentials_json"] = "/some/file.json"
cfg.Storage["path"] = "foo"
err := cfg.Validate()
Expect(err).To(MatchError("storage.path must be an absolute path"))
})
It("Handles Bad Dataset Type", func() {
cfg := rdd.NewConfiguration()
cfg.Storage["kind"] = "gs"
cfg.Storage["container"] = "test"
cfg.Storage["credentials_json"] = "/some/file.json"
cfg.DatasetType = "bar"
err := cfg.Validate()
Expect(err).To(MatchError("dataset_type must be one of: omop:5.2:csv"))
})
It("Handles Missing Dataset Type", func() {
cfg := rdd.NewConfiguration()
cfg.Storage["kind"] = "gs"
cfg.Storage["container"] = "test"
cfg.Storage["credentials_json"] = "/some/file.json"
err := cfg.Validate()
Expect(err).To(MatchError("dataset_type must be one of: omop:5.2:csv"))
})
})
Describe("ReadConfig", func() {
It("Works", func() {
content := []byte("{dataset_type: omop:5.2:csv, storage: {kind: s3, container: test, access_key: foo, secret_key: bar, region: baz}}")
file := makeTempFile(content)
defer os.Remove(file.Name())
cfg, err := rdd.ReadConfig(file.Name())
Expect(err).To(Succeed())
Expect(cfg.ConfigurationPath).To(Equal(file.Name()))
Expect(cfg.DatasetType).To(Equal("omop:5.2:csv"))
Expect(cfg.Storage["kind"]).To(Equal("s3"))
Expect(cfg.Storage["container"]).To(Equal("test"))
Expect(cfg.Storage["access_key"]).To(Equal("foo"))
Expect(cfg.Storage["secret_key"]).To(Equal("bar"))
Expect(cfg.Storage["region"]).To(Equal("baz"))
})
It("Handles missing files", func() {
_, err := rdd.ReadConfig("./doesntexist")
Expect(err).To(Not(Succeed()))
})
It("Handles bogus YAML", func() {
content := []byte("{garbage")
file := makeTempFile(content)
defer os.Remove(file.Name())
_, err := rdd.ReadConfig(file.Name())
Expect(err).To(Not(Succeed()))
})
})
})