Skip to content

Commit 7401054

Browse files
authored
Merge pull request moby#5158 from tonistiigi/testifylint-enable
lint: finish up testifylint
2 parents e83d79a + d7b3e02 commit 7401054

33 files changed

+404
-403
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ linters:
2323
- nolintlint
2424
- revive
2525
- staticcheck
26-
# - testifylint
26+
- testifylint
2727
- typecheck
2828
- unused
2929
- whitespace

cache/contenthash/checksum_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ func TestChecksumUnorderedFiles(t *testing.T) {
11201120
dgst, err := cc.Checksum(context.TODO(), ref, "d0", ChecksumOpts{FollowLinks: true}, nil)
11211121
require.NoError(t, err)
11221122

1123-
require.Equal(t, dgst, digest.Digest("sha256:14276c302c940a80f82ca5477bf766c98a24702d6a9948ee71bb277cdad3ae05"))
1123+
require.Equal(t, digest.Digest("sha256:14276c302c940a80f82ca5477bf766c98a24702d6a9948ee71bb277cdad3ae05"), dgst)
11241124

11251125
// check regression from earier version that didn't track some files
11261126
ch = []string{
@@ -1328,19 +1328,19 @@ func TestSymlinkInPathHandleChange(t *testing.T) {
13281328

13291329
dgstFileData0, err := cc.Checksum(context.TODO(), ref, "sub/d0", ChecksumOpts{FollowLinks: true}, nil)
13301330
require.NoError(t, err)
1331-
require.Equal(t, dgstFileData0, dgstDirD0)
1331+
require.Equal(t, dgstDirD0, dgstFileData0)
13321332

13331333
dgstFileData0, err = cc.Checksum(context.TODO(), ref, "d1/def/baz", ChecksumOpts{FollowLinks: true}, nil)
13341334
require.NoError(t, err)
1335-
require.Equal(t, dgstFileData0, dgstDirD0)
1335+
require.Equal(t, dgstDirD0, dgstFileData0)
13361336

13371337
dgstFileData0, err = cc.Checksum(context.TODO(), ref, "d1/def/bay", ChecksumOpts{FollowLinks: true}, nil)
13381338
require.NoError(t, err)
1339-
require.Equal(t, dgstFileData0, dgstDirD0)
1339+
require.Equal(t, dgstDirD0, dgstFileData0)
13401340

13411341
dgstFileData0, err = cc.Checksum(context.TODO(), ref, "link", ChecksumOpts{FollowLinks: true}, nil)
13421342
require.NoError(t, err)
1343-
require.Equal(t, dgstFileData0, dgstDirD0)
1343+
require.Equal(t, dgstDirD0, dgstFileData0)
13441344

13451345
err = ref.Release(context.TODO())
13461346
require.NoError(t, err)

cache/manager_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ func TestSetBlob(t *testing.T) {
718718
require.Equal(t, "", string(snapRef.getBlob()))
719719
require.Equal(t, "", string(snapRef.getChainID()))
720720
require.Equal(t, "", string(snapRef.getBlobChainID()))
721-
require.Equal(t, !snapRef.getBlobOnly(), true)
721+
require.Equal(t, true, !snapRef.getBlobOnly())
722722

723723
ctx, clean, err := leaseutil.WithLease(ctx, co.lm)
724724
require.NoError(t, err)
@@ -750,7 +750,7 @@ func TestSetBlob(t *testing.T) {
750750
require.Equal(t, snapRef.getDiffID(), snapRef.getChainID())
751751
require.Equal(t, digest.FromBytes([]byte(desc.Digest+" "+snapRef.getDiffID())), snapRef.getBlobChainID())
752752
require.Equal(t, snap.ID(), snapRef.getSnapshotID())
753-
require.Equal(t, !snapRef.getBlobOnly(), true)
753+
require.Equal(t, true, !snapRef.getBlobOnly())
754754

755755
active, err = cm.New(ctx, snap, nil)
756756
require.NoError(t, err)
@@ -776,7 +776,7 @@ func TestSetBlob(t *testing.T) {
776776
require.Equal(t, digest.FromBytes([]byte(snapRef.getChainID()+" "+snapRef2.getDiffID())), snapRef2.getChainID())
777777
require.Equal(t, digest.FromBytes([]byte(snapRef.getBlobChainID()+" "+digest.FromBytes([]byte(desc2.Digest+" "+snapRef2.getDiffID())))), snapRef2.getBlobChainID())
778778
require.Equal(t, snap2.ID(), snapRef2.getSnapshotID())
779-
require.Equal(t, !snapRef2.getBlobOnly(), true)
779+
require.Equal(t, true, !snapRef2.getBlobOnly())
780780

781781
b3, desc3, err := mapToBlob(map[string]string{"foo3": "bar3"}, true)
782782
require.NoError(t, err)
@@ -794,7 +794,7 @@ func TestSetBlob(t *testing.T) {
794794
require.Equal(t, digest.FromBytes([]byte(snapRef.getChainID()+" "+snapRef3.getDiffID())), snapRef3.getChainID())
795795
require.Equal(t, digest.FromBytes([]byte(snapRef.getBlobChainID()+" "+digest.FromBytes([]byte(desc3.Digest+" "+snapRef3.getDiffID())))), snapRef3.getBlobChainID())
796796
require.Equal(t, string(snapRef3.getChainID()), snapRef3.getSnapshotID())
797-
require.Equal(t, !snapRef3.getBlobOnly(), false)
797+
require.Equal(t, false, !snapRef3.getBlobOnly())
798798

799799
// snap4 is same as snap2
800800
snap4, err := cm.GetByBlob(ctx, desc2, snap)
@@ -840,7 +840,7 @@ func TestSetBlob(t *testing.T) {
840840
require.Equal(t, digest.FromBytes([]byte(snapRef3.getChainID()+" "+snapRef6.getDiffID())), snapRef6.getChainID())
841841
require.Equal(t, digest.FromBytes([]byte(snapRef3.getBlobChainID()+" "+digest.FromBytes([]byte(snapRef6.getBlob()+" "+snapRef6.getDiffID())))), snapRef6.getBlobChainID())
842842
require.Equal(t, string(snapRef6.getChainID()), snapRef6.getSnapshotID())
843-
require.Equal(t, !snapRef6.getBlobOnly(), false)
843+
require.Equal(t, false, !snapRef6.getBlobOnly())
844844

845845
_, err = cm.GetByBlob(ctx, ocispecs.Descriptor{
846846
Digest: digest.FromBytes([]byte("notexist")),
@@ -901,7 +901,7 @@ func TestPrune(t *testing.T) {
901901
require.NoError(t, err)
902902

903903
checkDiskUsage(ctx, t, cm, 2, 0)
904-
require.Equal(t, len(buf.all), 0)
904+
require.Equal(t, 0, len(buf.all))
905905

906906
dirs, err = os.ReadDir(filepath.Join(tmpdir, "snapshots/snapshots"))
907907
require.NoError(t, err)
@@ -919,7 +919,7 @@ func TestPrune(t *testing.T) {
919919
require.NoError(t, err)
920920

921921
checkDiskUsage(ctx, t, cm, 1, 0)
922-
require.Equal(t, len(buf.all), 1)
922+
require.Equal(t, 1, len(buf.all))
923923

924924
dirs, err = os.ReadDir(filepath.Join(tmpdir, "snapshots/snapshots"))
925925
require.NoError(t, err)
@@ -946,7 +946,7 @@ func TestPrune(t *testing.T) {
946946
require.NoError(t, err)
947947

948948
checkDiskUsage(ctx, t, cm, 2, 0)
949-
require.Equal(t, len(buf.all), 0)
949+
require.Equal(t, 0, len(buf.all))
950950

951951
// releasing last reference
952952
err = snap2.Release(ctx)
@@ -959,7 +959,7 @@ func TestPrune(t *testing.T) {
959959
require.NoError(t, err)
960960

961961
checkDiskUsage(ctx, t, cm, 0, 0)
962-
require.Equal(t, len(buf.all), 2)
962+
require.Equal(t, 2, len(buf.all))
963963

964964
dirs, err = os.ReadDir(filepath.Join(tmpdir, "snapshots/snapshots"))
965965
require.NoError(t, err)
@@ -1848,7 +1848,7 @@ func TestGetRemotes(t *testing.T) {
18481848
func checkVariantsCoverage(ctx context.Context, t *testing.T, variants idxToVariants, idx int, remotes []*solver.Remote, expectCompression *compression.Type) {
18491849
if idx < 0 {
18501850
for _, r := range remotes {
1851-
require.Equal(t, len(r.Descriptors), 0)
1851+
require.Equal(t, 0, len(r.Descriptors))
18521852
}
18531853
return
18541854
}
@@ -2081,7 +2081,7 @@ func TestMergeOp(t *testing.T) {
20812081
ms, unmount, err := m.Mount()
20822082
require.NoError(t, err)
20832083
require.Len(t, ms, 1)
2084-
require.Equal(t, ms[0].Type, "bind")
2084+
require.Equal(t, "bind", ms[0].Type)
20852085
err = fstest.CheckDirectoryEqualWithApplier(ms[0].Source, fstest.Apply(
20862086
fstest.CreateFile(strconv.Itoa(0), []byte(strconv.Itoa(0)), 0777),
20872087
))

cache/remotecache/v1/chains_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,31 @@ func TestSimpleMarshal(t *testing.T) {
3737
cfg, _, err := cc.Marshal(context.TODO())
3838
require.NoError(t, err)
3939

40-
require.Equal(t, len(cfg.Layers), 2)
41-
require.Equal(t, len(cfg.Records), 3)
40+
require.Equal(t, 2, len(cfg.Layers))
41+
require.Equal(t, 3, len(cfg.Records))
4242

4343
require.Equal(t, cfg.Layers[0].Blob, dgst("d0"))
44-
require.Equal(t, cfg.Layers[0].ParentIndex, -1)
44+
require.Equal(t, -1, cfg.Layers[0].ParentIndex)
4545
require.Equal(t, cfg.Layers[1].Blob, dgst("d1"))
46-
require.Equal(t, cfg.Layers[1].ParentIndex, 0)
46+
require.Equal(t, 0, cfg.Layers[1].ParentIndex)
4747

4848
require.Equal(t, cfg.Records[0].Digest, outputKey(dgst("baz"), 0))
49-
require.Equal(t, len(cfg.Records[0].Inputs), 2)
50-
require.Equal(t, len(cfg.Records[0].Results), 1)
49+
require.Equal(t, 2, len(cfg.Records[0].Inputs))
50+
require.Equal(t, 1, len(cfg.Records[0].Results))
5151

5252
require.Equal(t, cfg.Records[1].Digest, outputKey(dgst("foo"), 0))
53-
require.Equal(t, len(cfg.Records[1].Inputs), 0)
54-
require.Equal(t, len(cfg.Records[1].Results), 0)
53+
require.Equal(t, 0, len(cfg.Records[1].Inputs))
54+
require.Equal(t, 0, len(cfg.Records[1].Results))
5555

5656
require.Equal(t, cfg.Records[2].Digest, outputKey(dgst("bar"), 1))
57-
require.Equal(t, len(cfg.Records[2].Inputs), 0)
58-
require.Equal(t, len(cfg.Records[2].Results), 0)
57+
require.Equal(t, 0, len(cfg.Records[2].Inputs))
58+
require.Equal(t, 0, len(cfg.Records[2].Results))
5959

60-
require.Equal(t, cfg.Records[0].Results[0].LayerIndex, 1)
61-
require.Equal(t, cfg.Records[0].Inputs[0][0].Selector, "")
62-
require.Equal(t, cfg.Records[0].Inputs[0][0].LinkIndex, 1)
63-
require.Equal(t, cfg.Records[0].Inputs[1][0].Selector, "sel0")
64-
require.Equal(t, cfg.Records[0].Inputs[1][0].LinkIndex, 2)
60+
require.Equal(t, 1, cfg.Records[0].Results[0].LayerIndex)
61+
require.Equal(t, "", cfg.Records[0].Inputs[0][0].Selector)
62+
require.Equal(t, 1, cfg.Records[0].Inputs[0][0].LinkIndex)
63+
require.Equal(t, "sel0", cfg.Records[0].Inputs[1][0].Selector)
64+
require.Equal(t, 2, cfg.Records[0].Inputs[1][0].LinkIndex)
6565

6666
// adding same info again doesn't produce anything extra
6767
addRecords()
@@ -88,8 +88,8 @@ func TestSimpleMarshal(t *testing.T) {
8888
cfg, _, err = cc.Marshal(context.TODO())
8989
require.NoError(t, err)
9090

91-
require.Equal(t, len(cfg.Layers), 2)
92-
require.Equal(t, len(cfg.Records), 4)
91+
require.Equal(t, 2, len(cfg.Layers))
92+
require.Equal(t, 4, len(cfg.Records))
9393
}
9494

9595
func dgst(s string) digest.Digest {

client/client_nydus_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func testBuildExportNydusWithHybrid(t *testing.T, sb integration.Sandbox) {
8484
manifest, err := images.Manifest(ctx, contentStore, img.Target, nil)
8585
require.NoError(t, err)
8686

87-
require.Equal(t, len(manifest.Layers), 3)
87+
require.Len(t, manifest.Layers, 3)
8888
require.Equal(t, "true", manifest.Layers[0].Annotations[converter.LayerAnnotationNydusBlob])
8989
require.Equal(t, "true", manifest.Layers[1].Annotations[converter.LayerAnnotationNydusBlob])
9090
require.Equal(t, "true", manifest.Layers[2].Annotations[converter.LayerAnnotationNydusBootstrap])

0 commit comments

Comments
 (0)