From 09c3f0bb1b44a714b8e6040be4fbe91e8f1b7881 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Tue, 26 Jan 2021 18:15:47 +0000 Subject: [PATCH] Don't fail when adding a service to an environment with no pipelines. (#107) --- pkg/pipelines/service.go | 2 +- pkg/pipelines/service_test.go | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/pkg/pipelines/service.go b/pkg/pipelines/service.go index 5aa01aded..45acf9155 100644 --- a/pkg/pipelines/service.go +++ b/pkg/pipelines/service.go @@ -99,7 +99,7 @@ func serviceResources(m *config.Manifest, appFs afero.Fs, o *AddServiceOptions) secretsPath := filepath.Join(config.PathForPipelines(cfg), "base", secretFilename) files[secretsPath] = hookSecret - if o.ImageRepo != "" { + if o.ImageRepo != "" && env.Pipelines != nil { _, resources, bindingName, err := createImageRepoResources(m, cfg, env, o) if err != nil { return nil, err diff --git a/pkg/pipelines/service_test.go b/pkg/pipelines/service_test.go index a3b8b3d08..23a11e656 100644 --- a/pkg/pipelines/service_test.go +++ b/pkg/pipelines/service_test.go @@ -433,6 +433,44 @@ func TestServiceWithArgoCD(t *testing.T) { } } +func TestAddServiceWithImageWithNoPipelines(t *testing.T) { + defer stubDefaultPublicKeyFunc(t)() + + fakeFs := ioutils.NewMemoryFilesystem() + outputPath := afero.GetTempDir(fakeFs, "test") + pipelinesPath := filepath.Join(outputPath, pipelinesFile) + m := buildManifest(true, true) + m.Environments = append(m.Environments, &config.Environment{ + Name: "staging", + }) + b, err := yaml.Marshal(m) + assertNoError(t, err) + err = afero.WriteFile(fakeFs, pipelinesPath, b, 0644) + assertNoError(t, err) + wantedPaths := []string{ + "environments/staging/apps/new-app/services/test/base/config", + } + err = AddService(&AddServiceOptions{ + AppName: "new-app", + EnvName: "staging", + GitRepoURL: "http://github.com/org/test", + PipelinesFolderPath: outputPath, + ImageRepo: "testing/testing", + WebhookSecret: "123", + ServiceName: "test", + }, fakeFs) + assertNoError(t, err) + for _, path := range wantedPaths { + t.Run(fmt.Sprintf("checking path %s already exists", path), func(rt *testing.T) { + // The inmemory version of Afero doesn't return errors + exists, _ := fakeFs.DirExists(filepath.Join(outputPath, path)) + if !exists { + t.Fatalf("The directory does not exist at path : %v", path) + } + }) + } +} + func buildManifest(withPipelines, withArgoCD bool) *config.Manifest { m := config.Manifest{ GitOpsURL: "http://github.com/org/test",