From 55f5937073f5db097cd31f5cd0baa62594fa1906 Mon Sep 17 00:00:00 2001 From: Philip Laine Date: Tue, 14 May 2024 18:10:28 +0200 Subject: [PATCH] Enable testifylint linter --- .golangci.yaml | 3 +++ src/extensions/bigbang/bigbang_test.go | 23 ++++++++++------------- src/pkg/packager/lint/lint_test.go | 7 +++---- src/test/e2e/00_use_cli_test.go | 2 +- src/test/e2e/05_tarball_test.go | 2 +- src/test/e2e/21_connect_creds_test.go | 8 ++++---- src/test/e2e/51_oci_compose_test.go | 2 ++ src/test/external/ext_out_cluster_test.go | 4 ++++ 8 files changed, 28 insertions(+), 23 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 274226cc10..276faf17ae 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -11,6 +11,7 @@ linters: - goheader - goimports - nolintlint + - testifylint linters-settings: govet: enable-all: true @@ -50,6 +51,8 @@ linters-settings: - name: unused-parameter - name: unreachable-code - name: redefines-builtin-id + testifylint: + enable-all: true issues: # Revive rules that are disabled by default. include: diff --git a/src/extensions/bigbang/bigbang_test.go b/src/extensions/bigbang/bigbang_test.go index 21d09939f4..9d17e49831 100644 --- a/src/extensions/bigbang/bigbang_test.go +++ b/src/extensions/bigbang/bigbang_test.go @@ -12,29 +12,26 @@ import ( func TestRequiredBigBangVersions(t *testing.T) { // Support 1.54.0 and beyond vv, err := isValidVersion("1.54.0") - require.Equal(t, err, nil) - require.Equal(t, vv, true) + require.NoError(t, err) + require.True(t, vv) // Do not support earlier than 1.54.0 vv, err = isValidVersion("1.53.0") - require.Equal(t, err, nil) - require.Equal(t, vv, false) + require.NoError(t, err) + require.False(t, vv) // Support for Big Bang release candidates vv, err = isValidVersion("1.57.0-rc.0") - require.Equal(t, err, nil) - require.Equal(t, vv, true) + require.NoError(t, err) + require.True(t, vv) // Support for Big Bang 2.0.0 vv, err = isValidVersion("2.0.0") - require.Equal(t, err, nil) - require.Equal(t, vv, true) + require.NoError(t, err) + require.True(t, vv) // Fail on non-semantic versions vv, err = isValidVersion("1.57b") - Expected := "Invalid Semantic Version" - if err.Error() != Expected { - t.Errorf("Error actual = %v, and Expected = %v.", err, Expected) - } - require.Equal(t, vv, false) + require.EqualError(t, err, "Invalid Semantic Version") + require.False(t, vv) } diff --git a/src/pkg/packager/lint/lint_test.go b/src/pkg/packager/lint/lint_test.go index a0afd1a8a9..eba52b7743 100644 --- a/src/pkg/packager/lint/lint_test.go +++ b/src/pkg/packager/lint/lint_test.go @@ -119,7 +119,7 @@ func TestValidateSchema(t *testing.T) { "https://dev.azure.com/defenseunicorns/zarf-public-test/_git/zarf-public-test@v0.0.1"}} checkForUnpinnedRepos(&validator, &composer.Node{ZarfComponent: component}) require.Equal(t, unpinnedRepo, validator.findings[0].item) - require.Equal(t, len(validator.findings), 1) + require.Len(t, validator.findings, 1) }) t.Run("Unpinnned image warning", func(t *testing.T) { @@ -133,8 +133,7 @@ func TestValidateSchema(t *testing.T) { checkForUnpinnedImages(&validator, &composer.Node{ZarfComponent: component}) require.Equal(t, unpinnedImage, validator.findings[0].item) require.Equal(t, badImage, validator.findings[1].item) - require.Equal(t, 2, len(validator.findings)) - + require.Len(t, validator.findings, 2) }) t.Run("Unpinnned file warning", func(t *testing.T) { @@ -156,7 +155,7 @@ func TestValidateSchema(t *testing.T) { component := types.ZarfComponent{Files: zarfFiles} checkForUnpinnedFiles(&validator, &composer.Node{ZarfComponent: component}) require.Equal(t, fileURL, validator.findings[0].item) - require.Equal(t, 1, len(validator.findings)) + require.Len(t, validator.findings, 1) }) t.Run("Wrap standalone numbers in bracket", func(t *testing.T) { diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index 6b5a0e387c..e830139086 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -55,7 +55,7 @@ func TestUseCLI(t *testing.T) { // Test `zarf version` version, _, err := e2e.Zarf("version") require.NoError(t, err) - require.NotEqual(t, len(version), 0, "Zarf version should not be an empty string") + require.NotEmpty(t, version, "Zarf version should not be an empty string") version = strings.Trim(version, "\n") // test `zarf version --output=json` diff --git a/src/test/e2e/05_tarball_test.go b/src/test/e2e/05_tarball_test.go index 23eb39a7df..e929d3b420 100644 --- a/src/test/e2e/05_tarball_test.go +++ b/src/test/e2e/05_tarball_test.go @@ -51,7 +51,7 @@ func TestMultiPartPackage(t *testing.T) { require.NoError(t, err) err = json.Unmarshal(part0File, &pkgData) require.NoError(t, err) - require.Equal(t, pkgData.Count, 3) + require.Equal(t, 3, pkgData.Count) fmt.Printf("%#v", pkgData) stdOut, stdErr, err = e2e.Zarf("package", "deploy", deployPath, "--confirm") diff --git a/src/test/e2e/21_connect_creds_test.go b/src/test/e2e/21_connect_creds_test.go index a66d390f18..f7bc4ce25a 100644 --- a/src/test/e2e/21_connect_creds_test.go +++ b/src/test/e2e/21_connect_creds_test.go @@ -53,13 +53,13 @@ func TestConnectAndCreds(t *testing.T) { require.Contains(t, stdOut, "2.8.3") stdOut, stdErr, err = e2e.Zarf("tools", "registry", "ls", "127.0.0.1:31337/grafana/promtail") require.NoError(t, err, stdOut, stdErr) - require.Equal(t, stdOut, "") + require.Empty(t, stdOut) stdOut, stdErr, err = e2e.Zarf("tools", "registry", "ls", "127.0.0.1:31337/grafana/grafana") require.NoError(t, err, stdOut, stdErr) - require.Equal(t, stdOut, "") + require.Empty(t, stdOut) stdOut, stdErr, err = e2e.Zarf("tools", "registry", "ls", "127.0.0.1:31337/grafana/loki") require.NoError(t, err, stdOut, stdErr) - require.Equal(t, stdOut, "") + require.Empty(t, stdOut) } func TestMetrics(t *testing.T) { @@ -96,7 +96,7 @@ func TestMetrics(t *testing.T) { } desiredString := "go_gc_duration_seconds_count" - require.Equal(t, true, strings.Contains(string(body), desiredString)) + require.Contains(t, string(body), desiredString) require.NoError(t, err, resp) require.Equal(t, 200, resp.StatusCode) } diff --git a/src/test/e2e/51_oci_compose_test.go b/src/test/e2e/51_oci_compose_test.go index 052c5a1ee4..7c55e3238d 100644 --- a/src/test/e2e/51_oci_compose_test.go +++ b/src/test/e2e/51_oci_compose_test.go @@ -178,6 +178,8 @@ func (suite *SkeletonSuite) Test_2_FilePaths() { } func (suite *SkeletonSuite) DirOrFileExists(path string) { + suite.T().Helper() + invalid := helpers.InvalidPath(path) suite.Falsef(invalid, "path specified does not exist: %s", path) } diff --git a/src/test/external/ext_out_cluster_test.go b/src/test/external/ext_out_cluster_test.go index 2fd4178cf3..eeef4b94db 100644 --- a/src/test/external/ext_out_cluster_test.go +++ b/src/test/external/ext_out_cluster_test.go @@ -186,6 +186,8 @@ func (suite *ExtOutClusterTestSuite) Test_2_AuthToPrivateHelmChart() { } func (suite *ExtOutClusterTestSuite) createHelmChartInGitea(baseURL string, username string, password string) { + suite.T().Helper() + tempDir := suite.T().TempDir() podInfoVersion := "6.4.0" podinfoChartPath := filepath.Join("..", "..", "..", "examples", "helm-charts", "chart") @@ -223,6 +225,8 @@ func (suite *ExtOutClusterTestSuite) createHelmChartInGitea(baseURL string, user } func (suite *ExtOutClusterTestSuite) makeGiteaUserPrivate(baseURL string, username string, password string) { + suite.T().Helper() + url := fmt.Sprintf("%s/api/v1/admin/users/%s", baseURL, username) userOption := map[string]interface{}{