Skip to content

Commit

Permalink
Merge pull request #41 from bidhan-a/pipeline-tests
Browse files Browse the repository at this point in the history
Pipeline tests
  • Loading branch information
michelvocks committed Jul 19, 2018
2 parents 08f4a19 + da7bbd6 commit 60d338d
Showing 1 changed file with 124 additions and 0 deletions.
124 changes: 124 additions & 0 deletions pipeline/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ import (
"github.com/gaia-pipeline/gaia"
)

func TestAppend(t *testing.T) {
ap := NewActivePipelines()

p1 := gaia.Pipeline{
Name: "Pipeline A",
Type: gaia.PTypeGolang,
Created: time.Now(),
}
ap.Append(p1)

ret := ap.GetByName("Pipeline A")

if p1.Name != ret.Name || p1.Type != ret.Type {
t.Fatalf("Appended pipeline is not present in active pipelines.")
}

}

func TestRemove(t *testing.T) {
ap := NewActivePipelines()

Expand Down Expand Up @@ -39,6 +57,112 @@ func TestRemove(t *testing.T) {
}
}

func TestGetByName(t *testing.T) {
ap := NewActivePipelines()

p1 := gaia.Pipeline{
Name: "Pipeline A",
Type: gaia.PTypeGolang,
Created: time.Now(),
}
ap.Append(p1)

ret := ap.GetByName("Pipeline A")

if p1.Name != ret.Name || p1.Type != ret.Type {
t.Fatalf("Pipeline A should have been retrieved.")
}

ret = ap.GetByName("Pipeline B")
if ret != nil {
t.Fatalf("Pipeline B should not have been retrieved.")
}
}

func TestReplace(t *testing.T) {
ap := NewActivePipelines()

p1 := gaia.Pipeline{
Name: "Pipeline A",
Type: gaia.PTypeGolang,
Repo: gaia.GitRepo{
URL: "https://github.com/gaia-pipeline/go-test-example-1",
LocalDest: "tmp",
},
Created: time.Now(),
}
ap.Append(p1)

p2 := gaia.Pipeline{
Name: "Pipeline A",
Type: gaia.PTypeGolang,
Repo: gaia.GitRepo{
URL: "https://github.com/gaia-pipeline/go-test-example-2",
LocalDest: "tmp",
},
Created: time.Now(),
}
ap.Append(p2)

ret := ap.Replace(p2)
if !ret {
t.Fatalf("The pipeline could not be replaced")
}

p := ap.GetByName("Pipeline A")
if p.Repo.URL != "https://github.com/gaia-pipeline/go-test-example-2" {
t.Fatalf("The pipeline repo URL should have been replaced")
}
}

func TestIter(t *testing.T) {
ap := NewActivePipelines()

var pipelineNames = []string{"Pipeline A", "Pipeline B", "Pipeline C"}
var retrievedNames []string

for _, n := range pipelineNames {
p := gaia.Pipeline{
Name: n,
Type: gaia.PTypeGolang,
Created: time.Now(),
}
ap.Append(p)
}

count := 0
for pipeline := range ap.Iter() {
count++
retrievedNames = append(retrievedNames, pipeline.Name)
}

if count != len(pipelineNames) {
t.Fatalf("Expected %d pipelines. Got %d.", len(pipelineNames), count)
}

for i := range retrievedNames {
if pipelineNames[i] != retrievedNames[i] {
t.Fatalf("The pipeline names do not match")
}
}
}

func TestContains(t *testing.T) {
ap := NewActivePipelines()

p1 := gaia.Pipeline{
Name: "Pipeline A",
Type: gaia.PTypeGolang,
Created: time.Now(),
}
ap.Append(p1)

ret := ap.Contains("Pipeline A")
if !ret {
t.Fatalf("Expected Pipeline A to be present in active pipelines.")
}
}

func TestRemoveDeletedPipelines(t *testing.T) {
ap := NewActivePipelines()

Expand Down

0 comments on commit 60d338d

Please sign in to comment.