-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadapt_test.go
53 lines (44 loc) · 1 KB
/
adapt_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
package caddyyaml
import (
"encoding/json"
"io/ioutil"
"os"
"reflect"
"testing"
)
func TestApply(t *testing.T) {
tests := []struct {
filename string
environment string
}{
{filename: "test.caddy.json"},
{filename: "test.caddy.prod.json", environment: "production"},
}
for _, tt := range tests {
t.Run(tt.environment, func(t *testing.T) {
os.Setenv("ENVIRONMENT", tt.environment)
b, err := ioutil.ReadFile("./testdata/test.caddy.yaml")
if err != nil {
t.Fatal(err)
}
adaptedBytes, _, err := Adapter{}.Adapt(b, nil)
if err != nil {
t.Fatal(err)
}
jsonBytes, err := ioutil.ReadFile("./testdata/" + tt.filename)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(jsonToObj(adaptedBytes), jsonToObj(jsonBytes)) {
t.Log(string(adaptedBytes))
t.Fatal("adapter config does not match expected config")
}
})
}
}
func jsonToObj(b []byte) (obj map[string]interface{}) {
if err := json.Unmarshal(b, &obj); err != nil {
panic(err)
}
return
}