Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Don't fail when adding a service to an environment with no pipelines. (
Browse files Browse the repository at this point in the history
  • Loading branch information
bigkevmcd authored Jan 26, 2021
1 parent 1cdebab commit 09c3f0b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/pipelines/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions pkg/pipelines/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 09c3f0b

Please sign in to comment.