Skip to content
Open
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
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ linters:
- bool-compare
- len
- negative-positive
enable-all: true
usetesting:
context-background: true
context-todo: true
Expand Down
28 changes: 12 additions & 16 deletions cache/contenthash/checksum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/moby/buildkit/util/winlayers"
digest "github.com/opencontainers/go-digest"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tonistiigi/fsutil"
fstypes "github.com/tonistiigi/fsutil/types"
Expand Down Expand Up @@ -459,7 +460,7 @@ func TestChecksumWildcardWithBadMountable(t *testing.T) {
snapshotter, err := native.NewSnapshotter(filepath.Join(tmpdir, "snapshots"))
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, snapshotter.Close())
assert.NoError(t, snapshotter.Close())
})

cm, cleanup := setupCacheManager(t, tmpdir, "native", snapshotter)
Expand Down Expand Up @@ -512,12 +513,10 @@ func TestSymlinksNoFollow(t *testing.T) {
require.Equal(t, expectedSym, dgst)

_, err = cc.Checksum(t.Context(), ref, "foo/ghi", ChecksumOpts{FollowLinks: true, Wildcard: true}, nil) // same because broken symlink
require.Error(t, err)
require.Equal(t, true, errors.Is(err, errNotFound))
require.ErrorIs(t, err, errNotFound)

_, err = cc.Checksum(t.Context(), ref, "y1", ChecksumOpts{FollowLinks: true, Wildcard: true}, nil)
require.Error(t, err)
require.Equal(t, true, errors.Is(err, errNotFound))
require.ErrorIs(t, err, errNotFound)

dgst, err = cc.Checksum(t.Context(), ref, "sym", ChecksumOpts{}, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -611,8 +610,7 @@ func TestChecksumBasicFile(t *testing.T) {
require.Equal(t, dgstFileData0, dgst)

_, err = cc.Checksum(t.Context(), ref, "d0/ghi", ChecksumOpts{FollowLinks: true}, nil)
require.Error(t, err)
require.Equal(t, true, errors.Is(err, errNotFound))
require.ErrorIs(t, err, errNotFound)

dgst, err = cc.Checksum(t.Context(), ref, "/", ChecksumOpts{FollowLinks: true}, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -1000,7 +998,7 @@ func TestHandleChange(t *testing.T) {
snapshotter, err := native.NewSnapshotter(filepath.Join(tmpdir, "snapshots"))
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, snapshotter.Close())
assert.NoError(t, snapshotter.Close())
})

cm, cleanup := setupCacheManager(t, tmpdir, "native", snapshotter)
Expand Down Expand Up @@ -1062,12 +1060,10 @@ func TestHandleChange(t *testing.T) {
require.NoError(t, err)

_, err = cc.Checksum(t.Context(), ref, "d0", ChecksumOpts{FollowLinks: true}, nil)
require.Error(t, err)
require.Equal(t, true, errors.Is(err, errNotFound))
require.ErrorIs(t, err, errNotFound)

_, err = cc.Checksum(t.Context(), ref, "d0/abc", ChecksumOpts{FollowLinks: true}, nil)
require.Error(t, err)
require.Equal(t, true, errors.Is(err, errNotFound))
require.ErrorIs(t, err, errNotFound)

err = ref.Release(t.Context())
require.NoError(t, err)
Expand All @@ -1080,7 +1076,7 @@ func TestHandleRecursiveDir(t *testing.T) {
snapshotter, err := native.NewSnapshotter(filepath.Join(tmpdir, "snapshots"))
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, snapshotter.Close())
assert.NoError(t, snapshotter.Close())
})

cm, cleanup := setupCacheManager(t, tmpdir, "native", snapshotter)
Expand Down Expand Up @@ -1131,7 +1127,7 @@ func TestChecksumUnorderedFiles(t *testing.T) {
snapshotter, err := native.NewSnapshotter(filepath.Join(tmpdir, "snapshots"))
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, snapshotter.Close())
assert.NoError(t, snapshotter.Close())
})

cm, cleanup := setupCacheManager(t, tmpdir, "native", snapshotter)
Expand Down Expand Up @@ -1324,7 +1320,7 @@ func TestSymlinkInPathHandleChange(t *testing.T) {
snapshotter, err := native.NewSnapshotter(filepath.Join(tmpdir, "snapshots"))
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, snapshotter.Close())
assert.NoError(t, snapshotter.Close())
})

cm, cleanup := setupCacheManager(t, tmpdir, "native", snapshotter)
Expand Down Expand Up @@ -1443,7 +1439,7 @@ func TestChecksumUpdateDirectory(t *testing.T) {
snapshotter, err := native.NewSnapshotter(filepath.Join(tmpdir, "snapshots"))
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, snapshotter.Close())
assert.NoError(t, snapshotter.Close())
})

cm, cleanup := setupCacheManager(t, tmpdir, "native", snapshotter)
Expand Down
49 changes: 20 additions & 29 deletions cache/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import (
digest "github.com/opencontainers/go-digest"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
bolt "go.etcd.io/bbolt"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -209,7 +210,7 @@ func TestManager(t *testing.T) {
snapshotter, err := native.NewSnapshotter(filepath.Join(tmpdir, "snapshots"))
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, snapshotter.Close())
assert.NoError(t, snapshotter.Close())
})

co, cleanup, err := newCacheManager(ctx, t, cmOpt{
Expand Down Expand Up @@ -244,8 +245,7 @@ func TestManager(t *testing.T) {
require.NoError(t, err)

_, err = cm.GetMutable(ctx, active.ID())
require.Error(t, err)
require.Equal(t, true, errors.Is(err, ErrLocked))
require.ErrorIs(t, err, ErrLocked)

checkDiskUsage(ctx, t, cm, 1, 0)

Expand All @@ -255,8 +255,7 @@ func TestManager(t *testing.T) {
checkDiskUsage(ctx, t, cm, 1, 0)

_, err = cm.GetMutable(ctx, active.ID())
require.Error(t, err)
require.Equal(t, true, errors.Is(err, ErrLocked))
require.ErrorIs(t, err, ErrLocked)

err = snap.Release(ctx)
require.NoError(t, err)
Expand All @@ -280,12 +279,10 @@ func TestManager(t *testing.T) {
require.NoError(t, err)

_, err = cm.GetMutable(ctx, active.ID())
require.Error(t, err)
require.Equal(t, true, errors.Is(err, errNotFound))
require.ErrorIs(t, err, errNotFound)

_, err = cm.GetMutable(ctx, snap.ID())
require.Error(t, err)
require.Equal(t, true, errors.Is(err, errInvalid))
require.ErrorIs(t, err, errInvalid)

snap, err = cm.Get(ctx, snap.ID(), nil)
require.NoError(t, err)
Expand Down Expand Up @@ -605,7 +602,7 @@ func TestMissingMaterializedLowerDiffExtract(t *testing.T) {
ref, err := cm.GetByBlob(ctx, desc, nil)
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, ref.Release(context.WithoutCancel(ctx)))
assert.NoError(t, ref.Release(context.WithoutCancel(ctx)))
})
refs = append(refs, ref)
}
Expand All @@ -616,7 +613,7 @@ func TestMissingMaterializedLowerDiffExtract(t *testing.T) {
diff, err := cm.Diff(ctx, refs[0], refs[1], nil)
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, diff.Release(context.WithoutCancel(ctx)))
assert.NoError(t, diff.Release(context.WithoutCancel(ctx)))
})

lowerID := refs[0].(*immutableRef).getSnapshotID()
Expand Down Expand Up @@ -749,7 +746,7 @@ func TestSetBlob(t *testing.T) {
snapshotter, err := native.NewSnapshotter(filepath.Join(tmpdir, "snapshots"))
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, snapshotter.Close())
assert.NoError(t, snapshotter.Close())
})

co, cleanup, err := newCacheManager(ctx, t, cmOpt{
Expand Down Expand Up @@ -922,7 +919,7 @@ func TestPrune(t *testing.T) {
snapshotter, err := native.NewSnapshotter(filepath.Join(tmpdir, "snapshots"))
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, snapshotter.Close())
assert.NoError(t, snapshotter.Close())
})

co, cleanup, err := newCacheManager(ctx, t, cmOpt{
Expand Down Expand Up @@ -1034,7 +1031,7 @@ func TestLazyCommit(t *testing.T) {
snapshotter, err := native.NewSnapshotter(filepath.Join(tmpdir, "snapshots"))
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, snapshotter.Close())
assert.NoError(t, snapshotter.Close())
})

co, cleanup, err := newCacheManager(ctx, t, cmOpt{
Expand All @@ -1053,8 +1050,7 @@ func TestLazyCommit(t *testing.T) {
require.NoError(t, err)

_, err = cm.GetMutable(ctx, active.ID())
require.Error(t, err)
require.Equal(t, true, errors.Is(err, ErrLocked))
require.ErrorIs(t, err, ErrLocked)

// immutable refs still work
snap2, err := cm.Get(ctx, snap.ID(), nil)
Expand All @@ -1074,8 +1070,7 @@ func TestLazyCommit(t *testing.T) {

// active can't be get while immutable is held
_, err = cm.GetMutable(ctx, active.ID())
require.Error(t, err)
require.Equal(t, true, errors.Is(err, ErrLocked))
require.ErrorIs(t, err, ErrLocked)

err = snap.Release(ctx)
require.NoError(t, err)
Expand All @@ -1087,8 +1082,7 @@ func TestLazyCommit(t *testing.T) {

// because ref was took mutable old immutable are cleared
_, err = cm.Get(ctx, snap.ID(), nil)
require.Error(t, err)
require.Equal(t, true, errors.Is(err, errNotFound))
require.ErrorIs(t, err, errNotFound)

snap, err = active2.Commit(ctx)
require.NoError(t, err)
Expand All @@ -1102,8 +1096,7 @@ func TestLazyCommit(t *testing.T) {

// mutable is gone after finalize
_, err = cm.GetMutable(ctx, active2.ID())
require.Error(t, err)
require.Equal(t, true, errors.Is(err, errNotFound))
require.ErrorIs(t, err, errNotFound)

// immutable still works
snap2, err = cm.Get(ctx, snap.ID(), nil)
Expand Down Expand Up @@ -1145,8 +1138,7 @@ func TestLazyCommit(t *testing.T) {
require.NoError(t, err)

_, err = cm.Get(ctx, snap.ID(), nil)
require.Error(t, err)
require.Equal(t, true, errors.Is(err, errNotFound))
require.ErrorIs(t, err, errNotFound)

snap, err = active.Commit(ctx)
require.NoError(t, err)
Expand Down Expand Up @@ -1175,8 +1167,7 @@ func TestLazyCommit(t *testing.T) {
require.NoError(t, err)

_, err = cm.GetMutable(ctx, active.ID())
require.Error(t, err)
require.Equal(t, true, errors.Is(err, errNotFound))
require.ErrorIs(t, err, errNotFound)
}

func TestLoopLeaseContent(t *testing.T) {
Expand Down Expand Up @@ -1808,7 +1799,7 @@ func TestGetRemotes(t *testing.T) {
case compression.Zstd:
require.Equal(t, ocispecs.MediaTypeImageLayerZstd, desc.MediaType)
default:
require.Fail(t, "unhandled media type", compressionType)
t.Errorf("unhandled media type %s", compressionType)
}
dgst := desc.Digest
require.Contains(t, expectedContent, dgst, "for %v", compressionType)
Expand Down Expand Up @@ -2320,7 +2311,7 @@ func TestLoadHalfFinalizedRef(t *testing.T) {
snapshotter, err := native.NewSnapshotter(filepath.Join(tmpdir, "snapshots"))
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, snapshotter.Close())
assert.NoError(t, snapshotter.Close())
})

co, cleanup, err := newCacheManager(ctx, t, cmOpt{
Expand Down Expand Up @@ -2467,7 +2458,7 @@ func TestLoadBrokenParents(t *testing.T) {
snapshotter, err := native.NewSnapshotter(filepath.Join(tmpdir, "snapshots"))
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, snapshotter.Close())
assert.NoError(t, snapshotter.Close())
})

co, cleanup, err := newCacheManager(ctx, t, cmOpt{
Expand Down
5 changes: 2 additions & 3 deletions cache/util/fsutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ func TestSetErrorPath(t *testing.T) {
// Random path that shouldn't exist.
fpath := path.Join(dir, "a/b/c")
_, err := fsutil.Stat(fpath)
require.Error(t, err)

require.ErrorContains(t, err, "a/b/c")

// Set the path in the error to a new path.
replaceErrorPath(err, "/my/new/path")
require.NotContains(t, err.Error(), "a/b/c")
require.Contains(t, err.Error(), "/my/new/path")
require.ErrorContains(t, err, "/my/new/path")
}
6 changes: 2 additions & 4 deletions client/client_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,7 @@ func testCacheExportCacheDeletedContent(t *testing.T, sb integration.Sandbox) {
var runLayer *int
for i, l := range cc.Layers {
if l.ParentIndex != -1 {
if runLayer != nil {
t.Fatal("multiple RUN layers")
}
require.Nil(t, runLayer, "multiple RUN layers")
runLayer = &i
}
}
Expand Down Expand Up @@ -720,7 +718,7 @@ func testCacheExportIgnoreError(t *testing.T, sb integration.Sandbox) {
} else {
require.Error(t, err)
for _, errStr := range test.expectedErrors {
require.Contains(t, err.Error(), errStr)
require.ErrorContains(t, err, errStr)
}
}
})
Expand Down
5 changes: 1 addition & 4 deletions client/client_cdi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ devices:
},
},
}, nil)
require.Error(t, err)
require.ErrorContains(t, err, "requested by the build but not allowed")
}

Expand Down Expand Up @@ -455,8 +454,6 @@ func writeCDISpecFile(t *testing.T, sb integration.Sandbox, c *Client, csf ...cd
return
}

if now.After(deadline) {
t.Fatal("timeout waiting for CDI devices to appear")
}
require.LessOrEqualf(t, now, deadline, "timeout waiting for CDI devices to appear")
}
}
Loading