-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
86 lines (74 loc) · 1.32 KB
/
main_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
package main
import (
"log"
"testing"
"github.com/google/go-cmp/cmp"
)
func setUp() App {
return App{
Name: "jupyterhub",
Disable: false,
CookieInfo: Cookie{
Expiration: "48h",
CanaryPercent: .90,
IfSuccessful: KeyValue{
Key: "a",
Value: "a",
},
IfFail: KeyValue{
Key: "b",
Value: "b",
},
},
View: View{
ShowSuccess: true,
ShowFail: true,
},
Logging: Logging{
Disable: false,
},
}
}
func cleanUp(t *testing.T) {
app := setUp()
err := UpdateConfig(app)
if err != nil {
t.Fatal(err)
}
}
func TestReadConfig(t *testing.T) {
app := setUp()
config, err := ReadConfig()
shouldEqual := Config{
Apps: []App{
app,
},
Port: 8080,
}
if err != nil {
t.Fatalf(err.Error())
}
if len(config.Apps) != 1 {
t.Fatalf("Failed cookie length = %v", config.Apps)
}
log.Println(config)
if !cmp.Equal(config, shouldEqual) {
t.Fatalf("Failed equality to test = %v %v", config, shouldEqual)
}
}
func TestUpdateConfig(t *testing.T) {
app := setUp()
app.Logging.Disable = true
err := UpdateConfig(app)
if err != nil {
t.Fatal(err)
}
savedConfig, err := ReadConfig()
if err != nil {
t.Fatal(err)
}
defer cleanUp(t)
if !cmp.Equal(savedConfig.Apps[0], app) {
t.Fatalf("Failed equality test after update = %v %v", savedConfig.Apps[0], app)
}
}