From 1c571962d22788bce699e94d9288f2e7be03247d Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Thu, 14 Nov 2024 13:46:21 +0100 Subject: [PATCH] fixes --- cmd/bundle/generate/generate_test.go | 4 ++-- cmd/bundle/generate/job.go | 7 ++++--- cmd/bundle/generate/pipeline.go | 7 ++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cmd/bundle/generate/generate_test.go b/cmd/bundle/generate/generate_test.go index 943f721c..bfc9611a 100644 --- a/cmd/bundle/generate/generate_test.go +++ b/cmd/bundle/generate/generate_test.go @@ -90,7 +90,7 @@ func TestGeneratePipelineCommand(t *testing.T) { err := cmd.RunE(cmd, []string{}) require.NoError(t, err) - data, err := os.ReadFile(filepath.Join(configDir, "test_pipeline.yml")) + data, err := os.ReadFile(filepath.Join(configDir, "test_pipeline.pipeline.yml")) require.NoError(t, err) require.Equal(t, fmt.Sprintf(`resources: pipelines: @@ -186,7 +186,7 @@ func TestGenerateJobCommand(t *testing.T) { err := cmd.RunE(cmd, []string{}) require.NoError(t, err) - data, err := os.ReadFile(filepath.Join(configDir, "test_job.yml")) + data, err := os.ReadFile(filepath.Join(configDir, "test_job.job.yml")) require.NoError(t, err) require.Equal(t, fmt.Sprintf(`resources: diff --git a/cmd/bundle/generate/job.go b/cmd/bundle/generate/job.go index 15102ac4..ba204c59 100644 --- a/cmd/bundle/generate/job.go +++ b/cmd/bundle/generate/job.go @@ -1,7 +1,9 @@ package generate import ( + "errors" "fmt" + "io/fs" "os" "path/filepath" @@ -87,9 +89,8 @@ func NewGenerateJobCommand() *cobra.Command { filename := filepath.Join(configDir, fmt.Sprintf("%s.job.yml", jobKey)) err = os.Rename(oldFilename, filename) - if err != nil { - return fmt.Errorf("failed to rename file %s. DABs uses resource type as sub extension for generated content, please rename to %s", oldFilename, filename) - + if err != nil && !errors.Is(err, fs.ErrNotExist) { + return fmt.Errorf("failed to rename file %s. DABs uses resource type as sub extension for generated content, please rename to %s, err: %w", oldFilename, filename, err) } saver := yamlsaver.NewSaverWithStyle(map[string]yaml.Style{ diff --git a/cmd/bundle/generate/pipeline.go b/cmd/bundle/generate/pipeline.go index c7cd5c1d..9bce0b55 100644 --- a/cmd/bundle/generate/pipeline.go +++ b/cmd/bundle/generate/pipeline.go @@ -1,7 +1,9 @@ package generate import ( + "errors" "fmt" + "io/fs" "os" "path/filepath" @@ -87,9 +89,8 @@ func NewGeneratePipelineCommand() *cobra.Command { filename := filepath.Join(configDir, fmt.Sprintf("%s.pipeline.yml", pipelineKey)) err = os.Rename(oldFilename, filename) - if err != nil { - return fmt.Errorf("failed to rename file %s. DABs uses resource type as sub extension for generated content, please rename to %s", oldFilename, filename) - + if err != nil && !errors.Is(err, fs.ErrNotExist) { + return fmt.Errorf("failed to rename file %s. DABs uses resource type as sub extension for generated content, please rename to %s, err: %w", oldFilename, filename, err) } saver := yamlsaver.NewSaverWithStyle(