From 4ee76d1605c67a4a8e3c60a0e9b1067c2ca78edc Mon Sep 17 00:00:00 2001 From: David Lo Date: Fri, 6 Apr 2018 16:11:57 -0400 Subject: [PATCH] Default Triggers to empty slice (#32) --- pipeline/builder/builder.go | 2 ++ pipeline/builder/builder_test.go | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/pipeline/builder/builder.go b/pipeline/builder/builder.go index e1a0efc..a2576fd 100644 --- a/pipeline/builder/builder.go +++ b/pipeline/builder/builder.go @@ -46,6 +46,8 @@ func (b *Builder) Pipeline() (*types.SpinnakerPipeline, error) { sp.Notifications = buildNotifications(b.pipeline.Notifications) + sp.Triggers = []types.Trigger{} + for _, trigger := range b.pipeline.Triggers { if trigger.Jenkins != nil { jt := trigger.Jenkins diff --git a/pipeline/builder/builder_test.go b/pipeline/builder/builder_test.go index 0178fac..b655186 100644 --- a/pipeline/builder/builder_test.go +++ b/pipeline/builder/builder_test.go @@ -56,6 +56,44 @@ func TestBuilderPipelineStages(t *testing.T) { wd, _ := os.Getwd() file := filepath.Join(wd, "testdata", "deployment.full.yml") + t.Run("Triggers", func(t *testing.T) { + t.Run("Defaults to an empty slice", func(t *testing.T) { + pipeline := &config.Pipeline{} + + builder := builder.New(pipeline) + spinnaker, err := builder.Pipeline() + require.NoError(t, err, "error generating pipeline json") + + assert.Equal(t, []types.Trigger{}, spinnaker.Triggers) + }) + + t.Run("JenkinsTrigger is parsed correctly", func(t *testing.T) { + pipeline := &config.Pipeline{ + Triggers: []config.Trigger{ + { + Jenkins: &config.JenkinsTrigger{ + Job: "My Job Name", + Master: "namely-jenkins", + PropertyFile: ".test-ci-properties", + }, + }, + }, + } + + builder := builder.New(pipeline) + spinnaker, err := builder.Pipeline() + require.NoError(t, err, "error generating pipeline json") + + assert.Len(t, spinnaker.Triggers, 1) + + assert.Equal(t, true, spinnaker.Triggers[0].(*types.JenkinsTrigger).Enabled) + assert.Equal(t, "My Job Name", spinnaker.Triggers[0].(*types.JenkinsTrigger).Job) + assert.Equal(t, "namely-jenkins", spinnaker.Triggers[0].(*types.JenkinsTrigger).Master) + assert.Equal(t, ".test-ci-properties", spinnaker.Triggers[0].(*types.JenkinsTrigger).PropertyFile) + assert.Equal(t, "jenkins", spinnaker.Triggers[0].(*types.JenkinsTrigger).Type) + }) + }) + t.Run("Deploy stage is parsed correctly", func(t *testing.T) { t.Run("Clusters are assigned", func(t *testing.T) { pipeline := &config.Pipeline{