From 8185bfa41f9b7d373fac4511456800ae46ecc9c2 Mon Sep 17 00:00:00 2001 From: Devanshu Date: Tue, 5 Nov 2024 13:31:17 +0530 Subject: [PATCH 1/4] Return from RunWithCancel if cmd is kapp Signed-off-by: Devanshu --- cli/pkg/kctrl/cmd/app/release/release_cmd_runner.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cli/pkg/kctrl/cmd/app/release/release_cmd_runner.go b/cli/pkg/kctrl/cmd/app/release/release_cmd_runner.go index 6d5674dc8..0db52b5a0 100644 --- a/cli/pkg/kctrl/cmd/app/release/release_cmd_runner.go +++ b/cli/pkg/kctrl/cmd/app/release/release_cmd_runner.go @@ -35,9 +35,6 @@ func (r ReleaseCmdRunner) Run(cmd *goexec.Cmd) error { r.ui.PrintHeaderText("Building images and resolving references") } - if filepath.Base(cmd.Path) == "kapp" { - return nil - } if filepath.Base(cmd.Path) == "kbld" { cmd.Args = append(cmd.Args, fmt.Sprintf("--imgpkg-lock-output=%s", r.tempImgLockFilepath)) } @@ -57,6 +54,10 @@ func (r ReleaseCmdRunner) Run(cmd *goexec.Cmd) error { } func (r ReleaseCmdRunner) RunWithCancel(cmd *goexec.Cmd, cancelCh chan struct{}) error { + if filepath.Base(cmd.Path) == "kapp" { + return nil + } + if r.fullOutput { cmd.Stdout = io.MultiWriter(r.log, cmd.Stdout) cmd.Stderr = io.MultiWriter(r.log, cmd.Stderr) From 6566ae3ccf52a80ab68023829cf9ac68b54a6ddf Mon Sep 17 00:00:00 2001 From: Devanshu Date: Mon, 18 Nov 2024 16:30:06 +0530 Subject: [PATCH 2/4] Add test case to validate no err is returned when cmd is kapp Signed-off-by: Devanshu --- .../cmd/app/release/release_cmd_runner_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 cli/pkg/kctrl/cmd/app/release/release_cmd_runner_test.go diff --git a/cli/pkg/kctrl/cmd/app/release/release_cmd_runner_test.go b/cli/pkg/kctrl/cmd/app/release/release_cmd_runner_test.go new file mode 100644 index 000000000..0430b3ae0 --- /dev/null +++ b/cli/pkg/kctrl/cmd/app/release/release_cmd_runner_test.go @@ -0,0 +1,16 @@ +package release + +import ( + "os" + "os/exec" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestReleaseCmdRunnerForKappCmd(t *testing.T) { + ReleaseCmdRunner := NewReleaseCmdRunner(os.Stdout, false, "", false, nil) + cmd := exec.Command("kapp", "deploy", "-f", "-", "-a", "pkg-test", "-y") + err := ReleaseCmdRunner.RunWithCancel(cmd, nil) + require.NoError(t, err) +} From bd23c2b969887d6375ccb670ef2bf043f3a2a215 Mon Sep 17 00:00:00 2001 From: Devanshu Date: Tue, 19 Nov 2024 23:46:54 +0530 Subject: [PATCH 3/4] Add additional check for io noop Signed-off-by: Devanshu --- cli/pkg/kctrl/cmd/app/release/release_cmd_runner_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cli/pkg/kctrl/cmd/app/release/release_cmd_runner_test.go b/cli/pkg/kctrl/cmd/app/release/release_cmd_runner_test.go index 0430b3ae0..c4004950d 100644 --- a/cli/pkg/kctrl/cmd/app/release/release_cmd_runner_test.go +++ b/cli/pkg/kctrl/cmd/app/release/release_cmd_runner_test.go @@ -1,7 +1,7 @@ package release import ( - "os" + "bytes" "os/exec" "testing" @@ -9,8 +9,13 @@ import ( ) func TestReleaseCmdRunnerForKappCmd(t *testing.T) { - ReleaseCmdRunner := NewReleaseCmdRunner(os.Stdout, false, "", false, nil) + var buf bytes.Buffer + ReleaseCmdRunner := NewReleaseCmdRunner(&buf, false, "", false, nil) cmd := exec.Command("kapp", "deploy", "-f", "-", "-a", "pkg-test", "-y") err := ReleaseCmdRunner.RunWithCancel(cmd, nil) require.NoError(t, err) + expectedLength := 0 + if actualLength := buf.Len(); actualLength != expectedLength { + t.Errorf("Got Buffer length = %d, Expected empty", actualLength) + } } From 6cb1162994523fdfa9a1ee8bcaef50fd103784b3 Mon Sep 17 00:00:00 2001 From: Devanshu Date: Thu, 21 Nov 2024 21:17:08 +0530 Subject: [PATCH 4/4] Use require for empty assertion Signed-off-by: Devanshu --- cli/pkg/kctrl/cmd/app/release/release_cmd_runner_test.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cli/pkg/kctrl/cmd/app/release/release_cmd_runner_test.go b/cli/pkg/kctrl/cmd/app/release/release_cmd_runner_test.go index c4004950d..c29f62cdb 100644 --- a/cli/pkg/kctrl/cmd/app/release/release_cmd_runner_test.go +++ b/cli/pkg/kctrl/cmd/app/release/release_cmd_runner_test.go @@ -11,11 +11,8 @@ import ( func TestReleaseCmdRunnerForKappCmd(t *testing.T) { var buf bytes.Buffer ReleaseCmdRunner := NewReleaseCmdRunner(&buf, false, "", false, nil) - cmd := exec.Command("kapp", "deploy", "-f", "-", "-a", "pkg-test", "-y") + cmd := exec.Command("kapp", "deploy", "-f", "https://github.com/carvel-dev/kapp-controller/releases/latest/download/release.yml", "-a", "pkg-test", "-y") err := ReleaseCmdRunner.RunWithCancel(cmd, nil) require.NoError(t, err) - expectedLength := 0 - if actualLength := buf.Len(); actualLength != expectedLength { - t.Errorf("Got Buffer length = %d, Expected empty", actualLength) - } + require.Emptyf(t, buf.Len(), "Expected buf length 0 but got %d", buf.Len()) }