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

Don't fail when adding a service to an environment with no pipelines. #107

Merged
merged 1 commit into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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