From 040a18f9288d10b65ccb0da6e9d3051ce81f03c0 Mon Sep 17 00:00:00 2001 From: Fabian Reh Date: Tue, 27 Oct 2020 15:28:00 +0100 Subject: [PATCH] Reverts refactoring method --- cmd/gitopsUpdateDeployment.go | 22 +++++++--------------- cmd/gitopsUpdateDeployment_test.go | 12 ++++++------ 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/cmd/gitopsUpdateDeployment.go b/cmd/gitopsUpdateDeployment.go index 54c6d3218..0508bf545 100644 --- a/cmd/gitopsUpdateDeployment.go +++ b/cmd/gitopsUpdateDeployment.go @@ -120,9 +120,14 @@ func runGitopsUpdateDeployment(config *gitopsUpdateDeploymentOptions, command gi return errors.New("deploy tool " + config.DeployTool + " is not supported") } - commit, err := saveChanges(config, err, fileUtils, filePath, outputBytes, gitUtils) + err = fileUtils.FileWrite(filePath, outputBytes, 0755) if err != nil { - return errors.Wrap(err, "changes could not get saved") + return errors.Wrap(err, "failed to write file") + } + + commit, err := commitAndPushChanges(config, gitUtils) + if err != nil { + return errors.Wrap(err, "failed to commit and push changes") } log.Entry().Infof("Changes committed with %s", commit.String()) @@ -130,19 +135,6 @@ func runGitopsUpdateDeployment(config *gitopsUpdateDeploymentOptions, command gi return nil } -func saveChanges(config *gitopsUpdateDeploymentOptions, err error, fileUtils gitopsUpdateDeploymentFileUtils, filePath string, outputBytes []byte, gitUtils iGitopsUpdateDeploymentGitUtils) (plumbing.Hash, error) { - err = fileUtils.FileWrite(filePath, outputBytes, 0755) - if err != nil { - return plumbing.Hash{}, errors.Wrap(err, "failed to write file") - } - - commit, err := commitAndPushChanges(config, gitUtils) - if err != nil { - return plumbing.Hash{}, errors.Wrap(err, "failed to commit and push changes") - } - return commit, nil -} - func executeKubectl(config *gitopsUpdateDeploymentOptions, command gitopsUpdateDeploymentExecRunner, outputBytes []byte, filePath string) ([]byte, error) { registryImage, err := buildRegistryPlusImage(config) if err != nil { diff --git a/cmd/gitopsUpdateDeployment_test.go b/cmd/gitopsUpdateDeployment_test.go index eb7523e54..1946bc7cb 100644 --- a/cmd/gitopsUpdateDeployment_test.go +++ b/cmd/gitopsUpdateDeployment_test.go @@ -136,14 +136,14 @@ func TestRunGitopsUpdateDeploymentWithKubectl(t *testing.T) { gitUtils := &gitUtilsMock{failOnCommit: true} err := runGitopsUpdateDeployment(validConfiguration, &gitOpsExecRunnerMock{}, gitUtils, filesMock{}) - assert.EqualError(t, err, "changes could not get saved: failed to commit and push changes: committing changes failed: error on commit") + assert.EqualError(t, err, "failed to commit and push changes: committing changes failed: error on commit") }) t.Run("error on push commits", func(t *testing.T) { gitUtils := &gitUtilsMock{failOnPush: true} err := runGitopsUpdateDeployment(validConfiguration, &gitOpsExecRunnerMock{}, gitUtils, filesMock{}) - assert.EqualError(t, err, "changes could not get saved: failed to commit and push changes: pushing changes failed: error on push") + assert.EqualError(t, err, "failed to commit and push changes: pushing changes failed: error on push") }) t.Run("error on get working directory", func(t *testing.T) { @@ -164,7 +164,7 @@ func TestRunGitopsUpdateDeploymentWithKubectl(t *testing.T) { fileUtils := filesMock{failOnWrite: true} err := runGitopsUpdateDeployment(validConfiguration, &gitOpsExecRunnerMock{}, &gitUtilsMock{}, fileUtils) - assert.EqualError(t, err, "changes could not get saved: failed to write file: error appeared") + assert.EqualError(t, err, "failed to write file: error appeared") }) t.Run("error on temp dir deletion", func(t *testing.T) { @@ -291,14 +291,14 @@ func TestRunGitopsUpdateDeploymentWithHelm(t *testing.T) { gitUtils := &gitUtilsMock{failOnCommit: true} err := runGitopsUpdateDeployment(validConfiguration, &gitOpsExecRunnerMock{}, gitUtils, filesMock{}) - assert.EqualError(t, err, "changes could not get saved: failed to commit and push changes: committing changes failed: error on commit") + assert.EqualError(t, err, "failed to commit and push changes: committing changes failed: error on commit") }) t.Run("error on push commits", func(t *testing.T) { gitUtils := &gitUtilsMock{failOnPush: true} err := runGitopsUpdateDeployment(validConfiguration, &gitOpsExecRunnerMock{}, gitUtils, filesMock{}) - assert.EqualError(t, err, "changes could not get saved: failed to commit and push changes: pushing changes failed: error on push") + assert.EqualError(t, err, "failed to commit and push changes: pushing changes failed: error on push") }) t.Run("error on get working directory", func(t *testing.T) { @@ -319,7 +319,7 @@ func TestRunGitopsUpdateDeploymentWithHelm(t *testing.T) { fileUtils := filesMock{failOnWrite: true} err := runGitopsUpdateDeployment(validConfiguration, &gitOpsExecRunnerMock{}, &gitUtilsMock{}, fileUtils) - assert.EqualError(t, err, "changes could not get saved: failed to write file: error appeared") + assert.EqualError(t, err, "failed to write file: error appeared") }) t.Run("error on temp dir deletion", func(t *testing.T) {