-
Notifications
You must be signed in to change notification settings - Fork 2
/
config_test.go
145 lines (135 loc) · 3.14 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
package openlineage_test
import (
"testing"
"github.com/ThijsKoot/openlineage-go"
"github.com/ThijsKoot/openlineage-go/pkg/transport"
"github.com/go-test/deep"
)
func Test_ConfigFromEnv(t *testing.T) {
tests := []struct {
name string
env map[string]string
want openlineage.ClientConfig
}{
{
name: "console-pretty-print",
env: map[string]string{
"OPENLINEAGE_TRANSPORT": "console",
"OPENLINEAGE_PRETTY_PRINT": "true",
},
want: openlineage.ClientConfig{
Transport: transport.Config{
Type: transport.TransportTypeConsole,
Console: &transport.ConsoleConfig{
PrettyPrint: true,
},
HTTP: &transport.HTTPConfig{
Endpoint: transport.DefaultEndpoint,
},
},
Namespace: "default",
},
},
{
name: "http",
env: map[string]string{
"OPENLINEAGE_TRANSPORT": "http",
"OPENLINEAGE_URL": "https://foo",
"OPENLINEAGE_ENDPOINT": "bar/api/v1/lineage",
"OPENLINEAGE_NAMESPACE": "httpns",
},
want: openlineage.ClientConfig{
Transport: transport.Config{
Type: transport.TransportTypeHTTP,
HTTP: &transport.HTTPConfig{
URL: "https://foo",
Endpoint: "bar/api/v1/lineage",
},
},
Namespace: "httpns",
},
},
{
name: "file-env-combi",
env: map[string]string{
"OPENLINEAGE_CONFIG": "testdata/config-http.yaml",
"OPENLINEAGE_URL": "https://foo",
"OPENLINEAGE_NAMESPACE": "httpns",
},
want: openlineage.ClientConfig{
Transport: transport.Config{
Type: transport.TransportTypeHTTP,
HTTP: &transport.HTTPConfig{
URL: "https://foo",
Endpoint: "api/v1/lineage",
APIKey: "bar",
},
},
Namespace: "httpns",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
for k, v := range tt.env {
t.Setenv(k, v)
}
got, err := openlineage.ConfigFromEnv()
if err != nil {
t.Errorf("ConfigFromEnv failed: %s", err)
}
if diff := deep.Equal(tt.want, got); diff != nil {
t.Errorf("differences found:\n%s", diff)
}
})
}
}
func Test_ConfigFromFile(t *testing.T) {
cases := []struct {
name string
file string
want openlineage.ClientConfig
}{
{
name: "console",
file: "testdata/config-console.yaml",
want: openlineage.ClientConfig{
Transport: transport.Config{
Type: transport.TransportTypeConsole,
Console: &transport.ConsoleConfig{
PrettyPrint: true,
},
},
Namespace: "console-ns",
Disabled: false,
},
},
{
name: "http",
file: "testdata/config-http.yaml",
want: openlineage.ClientConfig{
Transport: transport.Config{
Type: transport.TransportTypeHTTP,
HTTP: &transport.HTTPConfig{
URL: "foo",
APIKey: "bar",
Endpoint: "api/v1/lineage",
},
},
Namespace: "http-ns",
Disabled: false,
},
},
}
for _, tt := range cases {
t.Run(tt.name, func(t *testing.T) {
got, err := openlineage.ConfigFromFile(tt.file)
if err != nil {
t.Fatalf("ConfigFromFile failed: %s", err.Error())
}
if diff := deep.Equal(tt.want, got); diff != nil {
t.Errorf("differences found:\n%s", diff)
}
})
}
}