@@ -4,13 +4,12 @@ import (
44"bytes"
55"errors"
66"io/ioutil"
7+ "strings"
78"testing"
89
10+ "github.com/gaia-pipeline/gaia"
911"github.com/gaia-pipeline/gaia/services"
10-
1112"github.com/gaia-pipeline/gaia/store"
12-
13- "github.com/gaia-pipeline/gaia"
1413"github.com/hashicorp/go-hclog"
1514)
1615
@@ -28,6 +27,16 @@ func (mcp *mockCreatePipelineStore) PipelinePut(p *gaia.Pipeline) error {
2827return mcp .Error
2928}
3029
30+ type mockScheduler struct {
31+ Error error
32+ }
33+
34+ func (ms * mockScheduler )Init ()error {return nil }
35+ func (ms * mockScheduler )SchedulePipeline (p * gaia.Pipeline ,args []gaia.Argument ) (* gaia.PipelineRun ,error ) {
36+ return nil ,nil
37+ }
38+ func (ms * mockScheduler )SetPipelineJobs (p * gaia.Pipeline )error {return ms .Error }
39+
3140func TestCreatePipelineUnknownType (t * testing.T ) {
3241tmp ,_ := ioutil .TempDir ("" ,"TestCreatePipelineUnknownType" )
3342gaia .Cfg = new (gaia.Config )
@@ -101,6 +110,7 @@ func TestCreatePipeline(t *testing.T) {
101110tmp ,_ := ioutil .TempDir ("" ,"TestCreatePipeline" )
102111gaia .Cfg = new (gaia.Config )
103112gaia .Cfg .HomePath = tmp
113+ gaia .Cfg .PipelinePath = tmp
104114buf := new (bytes.Buffer )
105115gaia .Cfg .Logger = hclog .New (& hclog.LoggerOptions {
106116Level :hclog .Trace ,
@@ -110,11 +120,43 @@ func TestCreatePipeline(t *testing.T) {
110120mcp := new (mockCreatePipelineStore )
111121services .MockStorageService (mcp )
112122defer func () {services .MockStorageService (nil ) }()
123+ ms := new (mockScheduler )
124+ services .MockSchedulerService (ms )
125+ defer func () {services .MockSchedulerService (nil ) }()
113126cp := new (gaia.CreatePipeline )
127+ cp .Pipeline .Name = "test"
114128cp .Pipeline .Type = gaia .PTypeGolang
115129cp .Pipeline .Repo .URL = "https://github.com/gaia-pipeline/pipeline-test"
116130CreatePipeline (cp )
117131if cp .StatusType != gaia .CreatePipelineSuccess {
118132t .Fatal ("pipeline status was not success. was: " ,cp .StatusType )
119133}
120134}
135+
136+ func TestCreatePipelineSetPipelineJobsFail (t * testing.T ) {
137+ tmp ,_ := ioutil .TempDir ("" ,"TestCreatePipelineSetPipelineJobsFail" )
138+ gaia .Cfg = new (gaia.Config )
139+ gaia .Cfg .HomePath = tmp
140+ gaia .Cfg .PipelinePath = tmp
141+ buf := new (bytes.Buffer )
142+ gaia .Cfg .Logger = hclog .New (& hclog.LoggerOptions {
143+ Level :hclog .Trace ,
144+ Output :buf ,
145+ Name :"Gaia" ,
146+ })
147+ mcp := new (mockCreatePipelineStore )
148+ services .MockStorageService (mcp )
149+ defer func () {services .MockStorageService (nil ) }()
150+ ms := new (mockScheduler )
151+ ms .Error = errors .New ("error" )
152+ services .MockSchedulerService (ms )
153+ defer func () {services .MockSchedulerService (nil ) }()
154+ cp := new (gaia.CreatePipeline )
155+ cp .Pipeline .Name = "test"
156+ cp .Pipeline .Type = gaia .PTypeGolang
157+ cp .Pipeline .Repo .URL = "https://github.com/gaia-pipeline/pipeline-test"
158+ CreatePipeline (cp )
159+ if ! strings .Contains (cp .Output ,"cannot validate pipeline" ) {
160+ t .Fatalf ("error thrown should contain 'cannot validate pipeline' but its %s" ,cp .Output )
161+ }
162+ }