-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstoplight_test.go
More file actions
129 lines (117 loc) · 1.95 KB
/
stoplight_test.go
File metadata and controls
129 lines (117 loc) · 1.95 KB
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
package main
import (
"bytes"
"log"
"strings"
"testing"
"github.com/spf13/viper"
)
var yamlExample = []byte(`
server:
url: http://localhost:8080/cc.xml
username: username
password: password
#only_projects:
projects:
- ^project
- f([a-z]+)_
- .*::.*::.*
- ^test
- mail
ignored_projects:
- ^project2
- ^foo_
- smail
- f([a-z]+)_
`)
func mockConfig() {
viper.SetConfigType("yaml")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()
if err := viper.ReadConfig(bytes.NewBuffer(yamlExample)); err != nil {
log.Fatalf("Error reading config, %s", err)
}
}
func TestXMLParser(t *testing.T) {
t.Skip("skipping test for now.")
}
func TestLastBuildStatus(t *testing.T) {
t.Skip("should convert XML attribute")
}
func TestCurrentStatus(t *testing.T) {
t.Skip("should convert XML attribute")
}
func TestExcludeFilter(t *testing.T) {
mockConfig()
type testpair struct {
arg Project
expected bool
}
tests := []testpair{
{
Project{Name: "foo_bar"},
false,
},
{
Project{Name: "smailer"},
false,
},
{
Project{Name: "project1"},
true,
},
{
Project{Name: "project2"},
false,
},
{
Project{Name: "project3"},
true,
},
}
for _, pair := range tests {
result := FilterExcludedProjects(pair.arg)
if result != pair.expected {
t.Error(
"For", pair.arg,
"Expected", pair.expected,
"Got", result,
)
}
}
}
func TestIncludeFilter(t *testing.T) {
mockConfig()
type testpair struct {
arg Project
expected bool
}
tests := []testpair{
{
Project{Name: "project1"},
true,
},
{
Project{Name: "project2"},
true,
},
{
Project{Name: "project3"},
true,
},
{
Project{Name: "nope"},
false,
},
}
for _, pair := range tests {
result := FilterIncludeProjects(pair.arg)
if result != pair.expected {
t.Error(
"For", pair.arg,
"Expected", pair.expected,
"Got", result,
)
}
}
}