Skip to content

Commit 60d338d

Browse files
authored
Merge pull request #41 from bidhan-a/pipeline-tests
Pipeline tests
2 parents 08f4a19 + da7bbd6 commit 60d338d

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

pipeline/pipeline_test.go

+124
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ import (
77
"github.com/gaia-pipeline/gaia"
88
)
99

10+
func TestAppend(t *testing.T) {
11+
ap := NewActivePipelines()
12+
13+
p1 := gaia.Pipeline{
14+
Name: "Pipeline A",
15+
Type: gaia.PTypeGolang,
16+
Created: time.Now(),
17+
}
18+
ap.Append(p1)
19+
20+
ret := ap.GetByName("Pipeline A")
21+
22+
if p1.Name != ret.Name || p1.Type != ret.Type {
23+
t.Fatalf("Appended pipeline is not present in active pipelines.")
24+
}
25+
26+
}
27+
1028
func TestRemove(t *testing.T) {
1129
ap := NewActivePipelines()
1230

@@ -39,6 +57,112 @@ func TestRemove(t *testing.T) {
3957
}
4058
}
4159

60+
func TestGetByName(t *testing.T) {
61+
ap := NewActivePipelines()
62+
63+
p1 := gaia.Pipeline{
64+
Name: "Pipeline A",
65+
Type: gaia.PTypeGolang,
66+
Created: time.Now(),
67+
}
68+
ap.Append(p1)
69+
70+
ret := ap.GetByName("Pipeline A")
71+
72+
if p1.Name != ret.Name || p1.Type != ret.Type {
73+
t.Fatalf("Pipeline A should have been retrieved.")
74+
}
75+
76+
ret = ap.GetByName("Pipeline B")
77+
if ret != nil {
78+
t.Fatalf("Pipeline B should not have been retrieved.")
79+
}
80+
}
81+
82+
func TestReplace(t *testing.T) {
83+
ap := NewActivePipelines()
84+
85+
p1 := gaia.Pipeline{
86+
Name: "Pipeline A",
87+
Type: gaia.PTypeGolang,
88+
Repo: gaia.GitRepo{
89+
URL: "https://github.com/gaia-pipeline/go-test-example-1",
90+
LocalDest: "tmp",
91+
},
92+
Created: time.Now(),
93+
}
94+
ap.Append(p1)
95+
96+
p2 := gaia.Pipeline{
97+
Name: "Pipeline A",
98+
Type: gaia.PTypeGolang,
99+
Repo: gaia.GitRepo{
100+
URL: "https://github.com/gaia-pipeline/go-test-example-2",
101+
LocalDest: "tmp",
102+
},
103+
Created: time.Now(),
104+
}
105+
ap.Append(p2)
106+
107+
ret := ap.Replace(p2)
108+
if !ret {
109+
t.Fatalf("The pipeline could not be replaced")
110+
}
111+
112+
p := ap.GetByName("Pipeline A")
113+
if p.Repo.URL != "https://github.com/gaia-pipeline/go-test-example-2" {
114+
t.Fatalf("The pipeline repo URL should have been replaced")
115+
}
116+
}
117+
118+
func TestIter(t *testing.T) {
119+
ap := NewActivePipelines()
120+
121+
var pipelineNames = []string{"Pipeline A", "Pipeline B", "Pipeline C"}
122+
var retrievedNames []string
123+
124+
for _, n := range pipelineNames {
125+
p := gaia.Pipeline{
126+
Name: n,
127+
Type: gaia.PTypeGolang,
128+
Created: time.Now(),
129+
}
130+
ap.Append(p)
131+
}
132+
133+
count := 0
134+
for pipeline := range ap.Iter() {
135+
count++
136+
retrievedNames = append(retrievedNames, pipeline.Name)
137+
}
138+
139+
if count != len(pipelineNames) {
140+
t.Fatalf("Expected %d pipelines. Got %d.", len(pipelineNames), count)
141+
}
142+
143+
for i := range retrievedNames {
144+
if pipelineNames[i] != retrievedNames[i] {
145+
t.Fatalf("The pipeline names do not match")
146+
}
147+
}
148+
}
149+
150+
func TestContains(t *testing.T) {
151+
ap := NewActivePipelines()
152+
153+
p1 := gaia.Pipeline{
154+
Name: "Pipeline A",
155+
Type: gaia.PTypeGolang,
156+
Created: time.Now(),
157+
}
158+
ap.Append(p1)
159+
160+
ret := ap.Contains("Pipeline A")
161+
if !ret {
162+
t.Fatalf("Expected Pipeline A to be present in active pipelines.")
163+
}
164+
}
165+
42166
func TestRemoveDeletedPipelines(t *testing.T) {
43167
ap := NewActivePipelines()
44168

0 commit comments

Comments
 (0)