/
reader_test.go
142 lines (118 loc) · 2.91 KB
/
reader_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
package config
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLoadSingleFile(t *testing.T) {
// Given
dir, _ := os.Getwd()
Filepath = dir + "/../tests/config/config.yaml"
MultipleFilepath = dir + "/../tests/config/config.unknown.*.yaml"
// When
conf, err := Load()
// Then
assert.IsType(t, new(Config), conf)
assert.Nil(t, err)
assert.Len(t, conf.Projects, 4)
assert.Equal(t, conf.Watcher.Exclude, []string{
".git",
"node_modules",
})
assert.Equal(t, conf.KubeConfig, "/home/test/.customkube/config")
}
func TestLoadMultipleFiles(t *testing.T) {
// Given
dir, _ := os.Getwd()
Filepath = dir + "/../tests/config/unknown.yaml"
MultipleFilepath = dir + "/../tests/config/config.multiple.*.yaml"
// Remove single config created file after test
defer os.Remove(Filepath)
// When
conf, err := Load()
// Then
assert.IsType(t, new(Config), conf)
assert.Nil(t, err)
assert.Len(t, conf.Projects, 4)
assert.Equal(t, conf.Watcher.Exclude, []string{
".git",
"node_modules",
"/event/an/absolute/path/in/multiple/files",
})
}
func TestGetProjectNames(t *testing.T) {
// Given
dir, _ := os.Getwd()
Filepath = dir + "/../tests/config/config.yaml"
MultipleFilepath = dir + "/../tests/config/config.unknown.*.yaml"
conf, err := Load()
// When
projectNames := conf.GetProjectNames()
// Then
assert.Nil(t, err)
assert.Equal(t, []string{
"full",
"graphql",
"forward-only",
"forward-composieux-website",
}, projectNames)
}
func TestGetProjectByName(t *testing.T) {
// Given
dir, _ := os.Getwd()
Filepath = dir + "/../tests/config/config.yaml"
MultipleFilepath = dir + "/../tests/config/config.unknown.*.yaml"
conf, err := Load()
// When
project, err := conf.GetProjectByName("forward-only")
// Then
assert.Nil(t, err)
assert.Equal(t, &Project{
Name: "forward-only",
Forwards: []*Forward{
&Forward{
Name: "graphql",
Type: "kubernetes",
Values: ForwardValues{
Context: "context-test",
Namespace: "backend",
Labels: map[string]string{
"app": "graphql",
},
Hostname: "graphql.svc.local",
Ports: []string{
"8080:8000",
},
},
},
&Forward{
Name: "grpc-api",
Type: "kubernetes",
Values: ForwardValues{
Context: "context-test",
Namespace: "backend",
Labels: map[string]string{
"app": "grpc-api",
},
Hostname: "grpc-api.svc.local",
Ports: []string{
"8080:8080",
},
},
},
},
}, project)
}
func TestGetProjectByNameWhenProjectNotFound(t *testing.T) {
// Given
dir, _ := os.Getwd()
Filepath = dir + "/../tests/config/config.yaml"
MultipleFilepath = dir + "/../tests/config/config.unknown.*.yaml"
conf, err := Load()
// When
project, err := conf.GetProjectByName("unknown-project")
// Then
assert.Nil(t, project)
assert.NotNil(t, err)
assert.Equal(t, "Unable to find project name 'unknown-project' in the configuration", err.Error())
}