-
Notifications
You must be signed in to change notification settings - Fork 10
/
source_test.go
48 lines (44 loc) · 1022 Bytes
/
source_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
package conf
import (
"testing"
)
type kinesisConfig struct {
StreamName string
}
type testConfig struct {
Kinesis kinesisConfig `conf:"kinesis"`
}
func TestEnvSource(t *testing.T) {
t.Run("Struct", func(t *testing.T) {
src := NewEnvSource("collector", "COLLECTOR_KINESIS_STREAM_NAME=blah")
a := testConfig{}
loader := Loader{
Name: "collector",
Args: []string{},
Sources: []Source{src},
}
if _, _, err := loader.Load(&a); err != nil {
t.Fatal(err)
}
if a.Kinesis.StreamName != "blah" {
t.Errorf("expected StreamName to get populated, got %q", a.Kinesis.StreamName)
}
})
t.Run("Map", func(t *testing.T) {
src := NewEnvSource("", "STREAM_NAME=blah")
cfg := struct {
StreamName string
}{}
loader := Loader{
Name: "collector",
Args: []string{},
Sources: []Source{src},
}
if _, _, err := loader.Load(&cfg); err != nil {
t.Fatal(err)
}
if cfg.StreamName != "blah" {
t.Errorf("expected 'blah' stream name, got %q", cfg.StreamName)
}
})
}