mirror of
https://github.com/helm/helm.git
synced 2026-08-06 08:01:19 +00:00
Merge pull request #32438 from mmorel-35/testifylint-manual-assert-pkg-22
chore(pkg): refactor: convert tests to testify assert/require part 22
This commit is contained in:
@@ -50,9 +50,7 @@ func TestHistoryRun(t *testing.T) {
|
||||
client.Max = 3
|
||||
client.cfg.Releases.MaxHistory = 3
|
||||
for _, rel := range []*release.Release{simpleRelease, updatedRelease} {
|
||||
if err := client.cfg.Releases.Create(rel); err != nil {
|
||||
t.Fatal(err, "Could not add releases to Config")
|
||||
}
|
||||
require.NoError(t, client.cfg.Releases.Create(rel), "Could not add releases to Config")
|
||||
}
|
||||
|
||||
releases, err := config.Releases.ListReleases()
|
||||
|
||||
@@ -401,16 +401,12 @@ data:
|
||||
serverSideApply := true
|
||||
err := configuration.execHook(&tc.inputRelease, hookEvent, kube.StatusWatcherStrategy, nil, 600, serverSideApply)
|
||||
|
||||
if !reflect.DeepEqual(kubeClient.deleteRecord, tc.expectedDeleteRecord) {
|
||||
t.Fatalf("Got unexpected delete record, expected: %#v, but got: %#v", kubeClient.deleteRecord, tc.expectedDeleteRecord)
|
||||
}
|
||||
require.Truef(t, reflect.DeepEqual(kubeClient.deleteRecord, tc.expectedDeleteRecord), "Got unexpected delete record, expected: %#v, but got: %#v", kubeClient.deleteRecord, tc.expectedDeleteRecord)
|
||||
|
||||
if err != nil && !tc.expectError {
|
||||
t.Fatal("Got an unexpected error.")
|
||||
}
|
||||
|
||||
if err == nil && tc.expectError {
|
||||
t.Fatal("Expected and error but did not get it.")
|
||||
if !tc.expectError {
|
||||
require.NoError(t, err)
|
||||
} else {
|
||||
require.Error(t, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -490,8 +486,7 @@ data:
|
||||
ctx := context.Background()
|
||||
waitOptions := []kube.WaitOption{kube.WithWaitContext(ctx)}
|
||||
|
||||
err := configuration.execHook(rel, release.HookPreInstall, kube.StatusWatcherStrategy, waitOptions, 600, false)
|
||||
req.NoError(err)
|
||||
req.NoError(configuration.execHook(rel, release.HookPreInstall, kube.StatusWatcherStrategy, waitOptions, 600, false))
|
||||
|
||||
// Verify that WaitOptions were passed to GetWaiter
|
||||
is.NotEmpty(failer.RecordedWaitOptions, "WaitOptions should be passed to GetWaiter")
|
||||
|
||||
@@ -190,8 +190,7 @@ func TestGetContainerLogs_MultipleContainers(t *testing.T) {
|
||||
rt := &ReleaseTesting{Namespace: "default"}
|
||||
|
||||
var buf bytes.Buffer
|
||||
err := rt.getContainerLogs(&buf, client, "test-pod")
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, rt.getContainerLogs(&buf, client, "test-pod"))
|
||||
output := buf.String()
|
||||
assert.Contains(t, output, "POD LOGS: test-pod (main)")
|
||||
assert.Contains(t, output, "POD LOGS: test-pod (sidecar)")
|
||||
@@ -217,8 +216,7 @@ func TestGetContainerLogs_WithInitContainers(t *testing.T) {
|
||||
rt := &ReleaseTesting{Namespace: "default"}
|
||||
|
||||
var buf bytes.Buffer
|
||||
err := rt.getContainerLogs(&buf, client, "test-pod")
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, rt.getContainerLogs(&buf, client, "test-pod"))
|
||||
output := buf.String()
|
||||
// Init containers should appear before regular containers
|
||||
assert.Contains(t, output, "POD LOGS: test-pod (init-setup)")
|
||||
@@ -230,8 +228,7 @@ func TestGetContainerLogs_PodNotFound(t *testing.T) {
|
||||
rt := &ReleaseTesting{Namespace: "default"}
|
||||
|
||||
var buf bytes.Buffer
|
||||
err := rt.getContainerLogs(&buf, client, "nonexistent-pod")
|
||||
assert.ErrorContains(t, err, "unable to get pod nonexistent-pod")
|
||||
assert.ErrorContains(t, rt.getContainerLogs(&buf, client, "nonexistent-pod"), "unable to get pod nonexistent-pod")
|
||||
}
|
||||
|
||||
func TestGetContainerLogs_OutputHeaderFormat(t *testing.T) {
|
||||
@@ -252,8 +249,7 @@ func TestGetContainerLogs_OutputHeaderFormat(t *testing.T) {
|
||||
rt := &ReleaseTesting{Namespace: "default"}
|
||||
|
||||
var buf bytes.Buffer
|
||||
err := rt.getContainerLogs(&buf, client, "multi-test")
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, rt.getContainerLogs(&buf, client, "multi-test"))
|
||||
output := buf.String()
|
||||
assert.Contains(t, output, "POD LOGS: multi-test (container-a)")
|
||||
assert.Contains(t, output, "POD LOGS: multi-test (container-b)")
|
||||
|
||||
@@ -17,6 +17,8 @@ package v2
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestValidateDependency(t *testing.T) {
|
||||
@@ -35,10 +37,10 @@ func TestValidateDependency(t *testing.T) {
|
||||
} {
|
||||
dep.Alias = value
|
||||
res := dep.Validate()
|
||||
if res != nil && !shouldFail {
|
||||
t.Errorf("Failed on case %q", dep.Alias)
|
||||
} else if res == nil && shouldFail {
|
||||
t.Errorf("Expected failure for %q", dep.Alias)
|
||||
if shouldFail {
|
||||
require.Errorf(t, res, "Expected failure for %q", dep.Alias)
|
||||
} else {
|
||||
require.NoErrorf(t, res, "Failed on case %q", dep.Alias)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package rules
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -28,17 +29,13 @@ func TestValidateNoDeprecations(t *testing.T) {
|
||||
Kind: "Deployment",
|
||||
}
|
||||
err := validateNoDeprecations(deprecated, nil)
|
||||
if err == nil {
|
||||
t.Fatal("Expected deprecated extension to be flagged")
|
||||
}
|
||||
require.Error(t, err, "Expected deprecated extension to be flagged")
|
||||
var depErr deprecatedAPIError
|
||||
require.ErrorAs(t, err, &depErr)
|
||||
require.NotEmptyf(t, depErr.Message, "Expected error message to be non-blank")
|
||||
|
||||
if err := validateNoDeprecations(&k8sYamlStruct{
|
||||
assert.NoError(t, validateNoDeprecations(&k8sYamlStruct{
|
||||
APIVersion: "v1",
|
||||
Kind: "Pod",
|
||||
}, nil); err != nil {
|
||||
t.Error("Expected a v1 Pod to not be deprecated")
|
||||
}
|
||||
}, nil), "Expected a v1 Pod to not be deprecated")
|
||||
}
|
||||
|
||||
@@ -17,7 +17,11 @@ limitations under the License.
|
||||
// Package version represents the current version of the project.
|
||||
package util
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestIsCompatibleRange(t *testing.T) {
|
||||
tests := []struct {
|
||||
@@ -36,8 +40,6 @@ func TestIsCompatibleRange(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
if IsCompatibleRange(tt.constraint, tt.ver) != tt.expected {
|
||||
t.Errorf("expected constraint %s to be %v for %s", tt.constraint, tt.expected, tt.ver)
|
||||
}
|
||||
assert.Equal(t, tt.expected, IsCompatibleRange(tt.constraint, tt.ver), "expected constraint %s to be %v for %s", tt.constraint, tt.expected, tt.ver)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,17 +56,14 @@ func runTestCmd(t *testing.T, tests []cmdTestCase) {
|
||||
|
||||
storage := storageFixture()
|
||||
for _, rel := range tt.rels {
|
||||
if err := storage.Create(rel); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, storage.Create(rel))
|
||||
}
|
||||
t.Logf("running cmd (attempt %d): %s", i+1, tt.cmd)
|
||||
_, out, err := executeActionCommandC(storage, tt.cmd)
|
||||
if tt.wantError && err == nil {
|
||||
t.Errorf("expected error, got success with the following output:\n%s", out)
|
||||
}
|
||||
if !tt.wantError && err != nil {
|
||||
t.Errorf("expected no error, got: '%v'", err)
|
||||
if tt.wantError {
|
||||
require.Error(t, err, "expected error, got success with the following output:\n%s", out)
|
||||
} else {
|
||||
require.NoError(t, err, "expected no error")
|
||||
}
|
||||
if tt.golden != "" {
|
||||
test.AssertGoldenString(t, out, tt.golden)
|
||||
@@ -294,8 +291,7 @@ func TestCmdGetDryRunFlagStrategy(t *testing.T) {
|
||||
|
||||
if tc.ExpectedLog != nil {
|
||||
logResult := map[string]string{}
|
||||
err = json.Unmarshal(logBuf.Bytes(), &logResult)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, json.Unmarshal(logBuf.Bytes(), &logResult))
|
||||
|
||||
assert.Equal(t, tc.ExpectedLog.Level, logResult["level"])
|
||||
assert.Equal(t, tc.ExpectedLog.Msg, logResult["msg"])
|
||||
|
||||
@@ -19,9 +19,11 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"helm.sh/helm/v4/pkg/repo/v1/repotest"
|
||||
)
|
||||
|
||||
@@ -32,9 +34,7 @@ func TestShowPreReleaseChart(t *testing.T) {
|
||||
)
|
||||
defer srv.Stop()
|
||||
|
||||
if err := srv.LinkIndices(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, srv.LinkIndices())
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -79,9 +79,7 @@ func TestShowPreReleaseChart(t *testing.T) {
|
||||
_, _, err := executeActionCommand(cmd)
|
||||
if err != nil {
|
||||
if tt.fail {
|
||||
if !strings.Contains(err.Error(), tt.expectedErr) {
|
||||
t.Errorf("%q expected error: %s, got: %s", tt.name, tt.expectedErr, err.Error())
|
||||
}
|
||||
assert.ErrorContains(t, err, tt.expectedErr, "%q expected error: %s, got: %s", tt.name, tt.expectedErr, err.Error())
|
||||
return
|
||||
}
|
||||
t.Errorf("%q reported error: %s", tt.name, err)
|
||||
|
||||
@@ -39,15 +39,13 @@ func (suite *HTTPRegistryClientTestSuite) TearDownSuite() {
|
||||
}
|
||||
|
||||
func (suite *HTTPRegistryClientTestSuite) Test_0_Login() {
|
||||
err := suite.RegistryClient.Login(suite.DockerRegistryHost,
|
||||
suite.Require().Error(suite.RegistryClient.Login(suite.DockerRegistryHost,
|
||||
LoginOptBasicAuth("badverybad", "ohsobad"),
|
||||
LoginOptPlainText(true))
|
||||
suite.Require().Error(err, "error logging into registry with bad credentials")
|
||||
LoginOptPlainText(true)), "error logging into registry with bad credentials")
|
||||
|
||||
err = suite.RegistryClient.Login(suite.DockerRegistryHost,
|
||||
suite.Require().NoError(suite.RegistryClient.Login(suite.DockerRegistryHost,
|
||||
LoginOptBasicAuth(testUsername, testPassword),
|
||||
LoginOptPlainText(true))
|
||||
suite.Require().NoError(err, "no error logging into registry with good credentials")
|
||||
LoginOptPlainText(true)), "no error logging into registry with good credentials")
|
||||
}
|
||||
|
||||
func (suite *HTTPRegistryClientTestSuite) Test_1_Push() {
|
||||
|
||||
@@ -73,10 +73,8 @@ type TestRegistry struct {
|
||||
|
||||
func setup(suite *TestRegistry, tlsEnabled, insecure bool, auth string) {
|
||||
suite.WorkspaceDir = testWorkspaceDir
|
||||
err := os.RemoveAll(suite.WorkspaceDir)
|
||||
suite.Require().NoError(err, "no error removing test workspace dir")
|
||||
err = os.Mkdir(suite.WorkspaceDir, 0o700)
|
||||
suite.Require().NoError(err, "no error creating test workspace dir")
|
||||
suite.Require().NoError(os.RemoveAll(suite.WorkspaceDir), "no error removing test workspace dir")
|
||||
suite.Require().NoError(os.Mkdir(suite.WorkspaceDir, 0o700), "no error creating test workspace dir")
|
||||
|
||||
var out bytes.Buffer
|
||||
|
||||
@@ -92,6 +90,7 @@ func setup(suite *TestRegistry, tlsEnabled, insecure bool, auth string) {
|
||||
ClientOptBasicAuth(testUsername, testPassword),
|
||||
}
|
||||
|
||||
var err error
|
||||
if tlsEnabled {
|
||||
var tlsConf *tls.Config
|
||||
if insecure {
|
||||
@@ -122,8 +121,7 @@ func setup(suite *TestRegistry, tlsEnabled, insecure bool, auth string) {
|
||||
pwBytes, err := bcrypt.GenerateFromPassword([]byte(testPassword), bcrypt.DefaultCost)
|
||||
suite.Require().NoError(err, "no error generating bcrypt password for test htpasswd file")
|
||||
htpasswdPath := filepath.Join(suite.WorkspaceDir, testHtpasswdFileBasename)
|
||||
err = os.WriteFile(htpasswdPath, fmt.Appendf(nil, "%s:%s\n", testUsername, string(pwBytes)), 0o644)
|
||||
suite.Require().NoError(err, "no error creating test htpasswd file")
|
||||
suite.Require().NoError(os.WriteFile(htpasswdPath, fmt.Appendf(nil, "%s:%s\n", testUsername, string(pwBytes)), 0o644), "no error creating test htpasswd file")
|
||||
|
||||
// Registry config
|
||||
config := &configuration.Configuration{}
|
||||
|
||||
Reference in New Issue
Block a user