-
Notifications
You must be signed in to change notification settings - Fork 52
/
ci_test.go
133 lines (108 loc) · 3.27 KB
/
ci_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
package ci_test
import (
"bytes"
"io/ioutil"
"os"
"sync"
"testing"
"github.com/commitdev/commit0/internal/config"
"github.com/commitdev/commit0/internal/generate/ci"
"github.com/commitdev/commit0/internal/templator"
"github.com/gobuffalo/packr/v2"
)
var testData = "../../test_data/ci/"
// setupTeardown removes all the generated test files before and after
// the test runs to ensure clean data.
func setupTeardown(t *testing.T) func(t *testing.T) {
os.RemoveAll("../../test_data/ci/actual")
return func(t *testing.T) {
os.RemoveAll("../../test_data/ci/actual")
}
}
func TestGenerateJenkins(t *testing.T) {
teardown := setupTeardown(t)
defer teardown(t)
templates := packr.New("templates", "../../../templates")
testTemplator := templator.NewTemplator(templates)
var waitgroup sync.WaitGroup
testConf := &config.Commit0Config{
Language: "go",
CI: config.CI{
System: "jenkins",
},
}
err := ci.Generate(testTemplator.CI, testConf, testData+"/actual", &waitgroup)
if err != nil {
t.Errorf("Error when executing test. %s", err)
}
waitgroup.Wait()
actual, err := ioutil.ReadFile(testData + "actual/Jenkinsfile")
if err != nil {
t.Errorf("Error reading created file: %s", err.Error())
}
expected, err := ioutil.ReadFile(testData + "/expected/Jenkinsfile")
if err != nil {
t.Errorf("Error reading created file: %s", err.Error())
}
if !bytes.Equal(expected, actual) {
t.Errorf("want:\n%s\n\n, got:\n%s\n\n", string(expected), string(actual))
}
}
func TestGenerateCircleCI(t *testing.T) {
teardown := setupTeardown(t)
defer teardown(t)
templates := packr.New("templates", "../../../templates")
testTemplator := templator.NewTemplator(templates)
var waitgroup sync.WaitGroup
testConf := &config.Commit0Config{
Language: "go",
CI: config.CI{
System: "circleci",
},
}
err := ci.Generate(testTemplator.CI, testConf, testData+"/actual", &waitgroup)
if err != nil {
t.Errorf("Error when executing test. %s", err)
}
waitgroup.Wait()
actual, err := ioutil.ReadFile(testData + "actual/.circleci/config.yml")
if err != nil {
t.Errorf("Error reading created file: %s", err.Error())
}
expected, err := ioutil.ReadFile(testData + "/expected/.circleci/config.yml")
if err != nil {
t.Errorf("Error reading created file: %s", err.Error())
}
if !bytes.Equal(expected, actual) {
t.Errorf("want:\n%s\n\ngot:\n%s\n\n", string(expected), string(actual))
}
}
func TestGenerateTravisCI(t *testing.T) {
teardown := setupTeardown(t)
defer teardown(t)
templates := packr.New("templates", "../../../templates")
testTemplator := templator.NewTemplator(templates)
var waitgroup sync.WaitGroup
testConf := &config.Commit0Config{
Language: "go",
CI: config.CI{
System: "travisci",
},
}
err := ci.Generate(testTemplator.CI, testConf, testData+"/actual", &waitgroup)
if err != nil {
t.Errorf("Error when executing test. %s", err)
}
waitgroup.Wait()
actual, err := ioutil.ReadFile(testData + "actual/.travis.yml")
if err != nil {
t.Errorf("Error reading created file: %s", err.Error())
}
expected, err := ioutil.ReadFile(testData + "/expected/.travis.yml")
if err != nil {
t.Errorf("Error reading created file: %s", err.Error())
}
if !bytes.Equal(expected, actual) {
t.Errorf("want:\n%s\n\n, got:\n%s\n\n", string(expected), string(actual))
}
}