-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_env_sourcer.go
52 lines (40 loc) · 977 Bytes
/
test_env_sourcer.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
package config
import (
"strings"
)
type testEnvSourcer struct {
values map[string]string
}
var _ Sourcer = &testEnvSourcer{}
// NewTestEnvSourcer creates a Sourcer that returns values from a given
// map.
func NewTestEnvSourcer(values map[string]string) Sourcer {
normalized := map[string]string{}
for key, value := range values {
normalized[strings.ToUpper(key)] = value
}
return &testEnvSourcer{
values: normalized,
}
}
func (s *testEnvSourcer) Init() error {
return nil
}
func (s *testEnvSourcer) Tags() []string {
return []string{EnvTag}
}
func (s *testEnvSourcer) Get(values []string) (string, SourcerFlag, error) {
if values[0] == "" {
return "", FlagSkip, nil
}
if val, ok := s.values[strings.ToUpper(values[0])]; ok {
return val, FlagFound, nil
}
return "", FlagMissing, nil
}
func (s *testEnvSourcer) Assets() []string {
return []string{"<test environment>"}
}
func (s *testEnvSourcer) Dump() map[string]string {
return s.values
}