refactor(cmd/helm): convert tests to testify assert/require

Replace native Go testing patterns (t.Errorf, t.Fatalf, t.Error,
t.Fatal) with github.com/stretchr/testify equivalents (assert.X,
require.X) for improved test readability and error messages.

Signed-off-by: George Jenkins <gvjenkins@gmail.com>
pull/32251/head
George Jenkins 1 week ago
parent ac4f8a6c22
commit ed76a36ab9

@ -18,13 +18,13 @@ package main
import (
"bytes"
"errors"
"os"
"os/exec"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCliPluginExitCode(t *testing.T) {
@ -62,20 +62,13 @@ func TestCliPluginExitCode(t *testing.T) {
err := cmd.Run()
exiterr := &exec.ExitError{}
ok := errors.As(err, &exiterr)
if !ok {
t.Fatalf("Unexpected error type returned by os.Exit: %T", err)
}
require.ErrorAs(t, err, &exiterr)
assert.Empty(t, stdout.String())
expectedStderr := "level=WARN msg=\"failed to load plugin (ignoring)\" plugin_yaml=../../pkg/cmd/testdata/helmhome/helm/plugins/noversion/plugin.yaml error=\"failed to load plugin \\\"../../pkg/cmd/testdata/helmhome/helm/plugins/noversion\\\": plugin `version` is required\"\nError: plugin \"exitwith\" exited with error\n"
if stderr.String() != expectedStderr {
t.Errorf("Expected %q written to stderr: Got %q", expectedStderr, stderr.String())
}
assert.Equal(t, expectedStderr, stderr.String())
if exiterr.ExitCode() != 43 {
t.Errorf("Expected exit code 43: Got %d", exiterr.ExitCode())
}
assert.Equal(t, 43, exiterr.ExitCode())
}
}

Loading…
Cancel
Save