-
Notifications
You must be signed in to change notification settings - Fork 0
/
resolver_test.go
90 lines (81 loc) · 1.92 KB
/
resolver_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
package vresolver
import (
"os"
"testing"
)
func TestCompose(t *testing.T) {
type args struct {
resolvers []Resolver
}
tests := []struct {
name string
input string
args args
want string
}{
{
name: "no resolver returns input value",
input: "foo",
args: args{resolvers: []Resolver{}},
want: "foo",
},
{
name: "single resolver that forwards input value",
input: "foo",
args: args{resolvers: []Resolver{func(arg string) string {
return arg
}}},
want: "foo",
},
{
name: "resolvers that mutate input value",
input: "foo",
args: args{resolvers: []Resolver{
func(input string) string {
return input
},
func(input string) string {
return input + "bar"
},
func(input string) string {
return input + "baz"
},
}},
want: "foobarbaz",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Compose(tt.args.resolvers...)(tt.input); got != tt.want {
t.Errorf("Compose() = %v, want %v", got, tt.want)
}
})
}
t.Run("non-empty env resolver with fallback resolver", func(t *testing.T) {
envvar := "foo"
os.Setenv(envvar, "bar")
defer os.Clearenv()
c := Compose(Env, Fallback("test"))
if got := c(envvar); got != "bar" {
t.Errorf("Composer(Env, Fallback) = %v, want %v", got, "bar")
}
})
t.Run("empty env resolver with fallback resolver", func(t *testing.T) {
c := Compose(Env, Fallback("test"))
if got := c("ghost"); got != "test" {
t.Errorf("Composer(Env, Fallback) = %v, want %v", got, "test")
}
})
t.Run("empty env, fallback to ecs no-tag metadata file, fallback to ecs metadata file", func(t *testing.T) {
c := Compose(
Env,
Fallback("./fixtures/ecs-metadata-no-tag.json"),
ECS,
Fallback("./fixtures/ecs-metadata.json"),
ECS,
)
if got := c("null"); got != "2.4" {
t.Errorf("Composer(Env, Fallback, ECS, Fallback, ECS)= %v, want %v", got, "2.4")
}
})
}