Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: testifylint fixes #753

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
run:
go: '1.20'
go: "1.20"
timeout: 5m
linters:
enable:
Expand All @@ -14,7 +14,7 @@ linters:
- tagliatelle
- misspell
- depguard

- testifylint
linters-settings:
forbidigo:
forbid:
Expand All @@ -29,5 +29,5 @@ linters-settings:
rules:
main:
deny:
- pkg: 'github.com/pkg/errors'
desc: 'use stdlib instead'
- pkg: "github.com/pkg/errors"
desc: "use stdlib instead"
8 changes: 4 additions & 4 deletions apk/apk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,13 +354,13 @@ func TestSignatureError(t *testing.T) {
require.Error(t, err)

var expectedError *nfpm.ErrSigningFailure
require.True(t, errors.As(err, &expectedError))
require.ErrorAs(t, err, &expectedError)

info.APK.Signature.KeyName = ""
info.Maintainer = ""
digest = sha1.New().Sum(nil) // nolint:gosec
err = createSignature(&signatureTarGz, info, digest)
require.True(t, errors.As(err, &expectedError))
require.ErrorAs(t, err, &expectedError)
}

func TestSignatureCallback(t *testing.T) {
Expand Down Expand Up @@ -575,8 +575,8 @@ func TestDirectories(t *testing.T) {
require.Equal(t, h.Typeflag, byte(tar.TypeDir))
h = extractFileHeaderFromTar(t, buf.Bytes(), "/etc/bar")
require.Equal(t, h.Typeflag, byte(tar.TypeDir))
require.Equal(t, h.Mode, int64(0o700))
require.Equal(t, h.Uname, "test")
require.Equal(t, int64(0o700), h.Mode)
require.Equal(t, "test", h.Uname)
h = extractFileHeaderFromTar(t, buf.Bytes(), "/etc/baz")
require.Equal(t, h.Typeflag, byte(tar.TypeDir))
}
Expand Down
14 changes: 7 additions & 7 deletions deb/deb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,13 +786,13 @@ func TestMD5Sums(t *testing.T) {
md5sumsFile := extractFileFromTar(t, inflate(t, "gz", controlTarGz), "./md5sums")

lines := strings.Split(strings.TrimRight(string(md5sumsFile), "\n"), "\n")
require.Equal(t, nFiles, len(lines), string(md5sumsFile))
require.Len(t, lines, nFiles, string(md5sumsFile))

dataTar := inflate(t, tarballName, dataTarball)

for _, line := range lines {
parts := strings.Fields(line)
require.Equal(t, len(parts), 2)
require.Len(t, parts, 2)

md5sum, fileName := parts[0], parts[1]

Expand Down Expand Up @@ -858,8 +858,8 @@ func TestDirectories(t *testing.T) {
require.Equal(t, h.Typeflag, byte(tar.TypeDir))
h = extractFileHeaderFromTar(t, dataTarball, "/etc/bar")
require.Equal(t, h.Typeflag, byte(tar.TypeDir))
require.Equal(t, h.Mode, int64(0o700))
require.Equal(t, h.Uname, "test")
require.Equal(t, int64(0o700), h.Mode)
require.Equal(t, "test", h.Uname)
h = extractFileHeaderFromTar(t, dataTarball, "/etc/baz")
require.Equal(t, h.Typeflag, byte(tar.TypeDir))

Expand Down Expand Up @@ -963,7 +963,7 @@ func TestDebsigsSignatureError(t *testing.T) {
require.Error(t, err)

var expectedError *nfpm.ErrSigningFailure
require.True(t, errors.As(err, &expectedError))
require.ErrorAs(t, err, &expectedError)
}

func TestDebsigsSignatureCallback(t *testing.T) {
Expand Down Expand Up @@ -1015,7 +1015,7 @@ func TestDpkgSigSignatureError(t *testing.T) {
require.Error(t, err)

var expectedError *nfpm.ErrSigningFailure
require.True(t, errors.As(err, &expectedError))
require.ErrorAs(t, err, &expectedError)
}

func TestDpkgSigSignatureCallback(t *testing.T) {
Expand Down Expand Up @@ -1183,7 +1183,7 @@ func TestIgnoreUnrelatedFiles(t *testing.T) {
require.NoError(t, err)

contents := tarContents(t, inflate(t, tarballName, dataTarball))
require.Len(t, contents, 0)
require.Empty(t, contents)
}

func extractFileFromTar(tb testing.TB, tarFile []byte, filename string) []byte {
Expand Down
14 changes: 7 additions & 7 deletions files/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ contents:
require.Len(t, config.Contents, 2)
for _, f := range config.Contents {
t.Logf("%+#v\n", f)
require.Equal(t, f.Source, "a")
require.Equal(t, f.Destination, "b")
require.Equal(t, "a", f.Source)
require.Equal(t, "b", f.Destination)
}
}

Expand Down Expand Up @@ -157,8 +157,8 @@ contents:
require.NoError(t, err)

f := config.Contents[0]
require.Equal(t, f.Source, "files_test.go")
require.Equal(t, f.Destination, "/b")
require.Equal(t, "files_test.go", f.Source)
require.Equal(t, "/b", f.Destination)
require.Equal(t, f.FileInfo.Mode, fi.Mode())
require.Equal(t, f.FileInfo.MTime, fi.ModTime())
}
Expand Down Expand Up @@ -193,8 +193,8 @@ contents:
require.NoError(t, err)

f := config.Contents[0]
require.Equal(t, f.Source, "files_test.go")
require.Equal(t, f.Destination, "/b")
require.Equal(t, "files_test.go", f.Source)
require.Equal(t, "/b", f.Destination)
require.Equal(t, f.FileInfo.Mode, os.FileMode(0o123))
require.Equal(t, f.FileInfo.MTime, ct)
}
Expand Down Expand Up @@ -603,7 +603,7 @@ func TestImplicitDirectories(t *testing.T) {
},
}

require.Equal(t, withoutFileInfo(results), expected)
require.Equal(t, expected, withoutFileInfo(results))
}

func TestRelevantFiles(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions internal/sign/pgp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package sign

import (
"bytes"
"errors"
"fmt"
"os"
"testing"
Expand Down Expand Up @@ -106,7 +105,7 @@ func TestPGPSignerError(t *testing.T) {
require.Error(t, err)

var expectedError *nfpm.ErrSigningFailure
require.True(t, errors.As(err, &expectedError))
require.ErrorAs(t, err, &expectedError)
}

func TestNoSigningKey(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions nfpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,13 +563,13 @@ func TestOverrides(t *testing.T) {
t.Run(format, func(t *testing.T) {
pkg, err := config.Get(format)
require.NoError(t, err)
require.Equal(t, pkg.Depends, []string{format + "_depend"})
require.Equal(t, []string{format + "_depend"}, pkg.Depends)
for _, f := range pkg.Contents {
switch f.Packager {
case format:
require.Contains(t, f.Destination, "/"+format)
case "":
require.True(t, f.Destination == "/etc/foo/whatever.conf")
require.Equal(t, "/etc/foo/whatever.conf", f.Destination)
default:
t.Fatalf("invalid packager: %s", f.Packager)
}
Expand Down
6 changes: 3 additions & 3 deletions rpm/rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ func TestRPMSignatureError(t *testing.T) {
require.Error(t, err)

var expectedError *nfpm.ErrSigningFailure
require.True(t, errors.As(err, &expectedError))
require.ErrorAs(t, err, &expectedError)
}

func TestRPMSignatureCallback(t *testing.T) {
Expand Down Expand Up @@ -892,7 +892,7 @@ func TestDirectories(t *testing.T) {
// claiming explicit ownership of /etc/bar which already contains a file
h, err := extractFileHeaderFromRpm(rpmFileBuffer.Bytes(), "/etc/bar")
require.NoError(t, err)
require.NotEqual(t, h.Mode()&int(tagDirectory), 0)
require.NotEqual(t, 0, h.Mode()&int(tagDirectory))

// creating an empty folder (which also implies ownership)
h, err = extractFileHeaderFromRpm(rpmFileBuffer.Bytes(), "/etc/baz")
Expand Down Expand Up @@ -931,7 +931,7 @@ func TestIgnoreUnrelatedFiles(t *testing.T) {
err := Default.Package(info, &rpmFileBuffer)
require.NoError(t, err)

require.Len(t, getTree(t, rpmFileBuffer.Bytes()), 0)
require.Empty(t, getTree(t, rpmFileBuffer.Bytes()))
}

func extractFileFromRpm(rpm []byte, filename string) ([]byte, error) {
Expand Down
Loading