Migrate to gotestyourself/assert

Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
Daniel Nephin 2018-01-23 12:06:06 -05:00
parent 1719a6e17a
commit ef48a0268e
13 changed files with 113 additions and 108 deletions

View File

@ -15,8 +15,8 @@ import (
"testing" "testing"
"github.com/containerd/fifo" "github.com/containerd/fifo"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
"github.com/stretchr/testify/require" is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func assertHasPrefix(t *testing.T, s, prefix string) { func assertHasPrefix(t *testing.T, s, prefix string) {
@ -32,28 +32,28 @@ func TestNewFIFOSetInDir(t *testing.T) {
} }
root, err := ioutil.TempDir("", "test-new-fifo-set") root, err := ioutil.TempDir("", "test-new-fifo-set")
require.NoError(t, err) assert.NilError(t, err)
defer os.RemoveAll(root) defer os.RemoveAll(root)
fifos, err := NewFIFOSetInDir(root, "theid", true) fifos, err := NewFIFOSetInDir(root, "theid", true)
require.NoError(t, err) assert.NilError(t, err)
assertHasPrefix(t, fifos.Stdin, root) assertHasPrefix(t, fifos.Stdin, root)
assertHasPrefix(t, fifos.Stdout, root) assertHasPrefix(t, fifos.Stdout, root)
assertHasPrefix(t, fifos.Stderr, root) assertHasPrefix(t, fifos.Stderr, root)
assert.Equal(t, "theid-stdin", filepath.Base(fifos.Stdin)) assert.Check(t, is.Equal("theid-stdin", filepath.Base(fifos.Stdin)))
assert.Equal(t, "theid-stdout", filepath.Base(fifos.Stdout)) assert.Check(t, is.Equal("theid-stdout", filepath.Base(fifos.Stdout)))
assert.Equal(t, "theid-stderr", filepath.Base(fifos.Stderr)) assert.Check(t, is.Equal("theid-stderr", filepath.Base(fifos.Stderr)))
assert.Equal(t, true, fifos.Terminal) assert.Check(t, is.Equal(true, fifos.Terminal))
files, err := ioutil.ReadDir(root) files, err := ioutil.ReadDir(root)
require.NoError(t, err) assert.NilError(t, err)
assert.Len(t, files, 1) assert.Check(t, is.Len(files, 1))
require.NoError(t, fifos.Close()) assert.NilError(t, fifos.Close())
files, err = ioutil.ReadDir(root) files, err = ioutil.ReadDir(root)
require.NoError(t, err) assert.NilError(t, err)
assert.Len(t, files, 0) assert.Check(t, is.Len(files, 0))
} }
func TestNewAttach(t *testing.T) { func TestNewAttach(t *testing.T) {
@ -75,25 +75,25 @@ func TestNewAttach(t *testing.T) {
attacher := NewAttach(withBytesBuffers) attacher := NewAttach(withBytesBuffers)
fifos, err := NewFIFOSetInDir("", "theid", false) fifos, err := NewFIFOSetInDir("", "theid", false)
require.NoError(t, err) assert.NilError(t, err)
io, err := attacher(fifos) io, err := attacher(fifos)
require.NoError(t, err) assert.NilError(t, err)
defer io.Close() defer io.Close()
producers := setupFIFOProducers(t, io.Config()) producers := setupFIFOProducers(t, io.Config())
initProducers(t, producers, expectedStdout, expectedStderr) initProducers(t, producers, expectedStdout, expectedStderr)
actualStdin, err := ioutil.ReadAll(producers.Stdin) actualStdin, err := ioutil.ReadAll(producers.Stdin)
require.NoError(t, err) assert.NilError(t, err)
io.Wait() io.Wait()
io.Cancel() io.Cancel()
assert.NoError(t, io.Close()) assert.Check(t, is.NilError(io.Close()))
assert.Equal(t, expectedStdout, stdout.String()) assert.Check(t, is.Equal(expectedStdout, stdout.String()))
assert.Equal(t, expectedStderr, stderr.String()) assert.Check(t, is.Equal(expectedStderr, stderr.String()))
assert.Equal(t, expectedStdin, string(actualStdin)) assert.Check(t, is.Equal(expectedStdin, string(actualStdin)))
} }
type producers struct { type producers struct {
@ -110,23 +110,23 @@ func setupFIFOProducers(t *testing.T, fifos Config) producers {
) )
pipes.Stdin, err = fifo.OpenFifo(ctx, fifos.Stdin, syscall.O_RDONLY, 0) pipes.Stdin, err = fifo.OpenFifo(ctx, fifos.Stdin, syscall.O_RDONLY, 0)
require.NoError(t, err) assert.NilError(t, err)
pipes.Stdout, err = fifo.OpenFifo(ctx, fifos.Stdout, syscall.O_WRONLY, 0) pipes.Stdout, err = fifo.OpenFifo(ctx, fifos.Stdout, syscall.O_WRONLY, 0)
require.NoError(t, err) assert.NilError(t, err)
pipes.Stderr, err = fifo.OpenFifo(ctx, fifos.Stderr, syscall.O_WRONLY, 0) pipes.Stderr, err = fifo.OpenFifo(ctx, fifos.Stderr, syscall.O_WRONLY, 0)
require.NoError(t, err) assert.NilError(t, err)
return pipes return pipes
} }
func initProducers(t *testing.T, producers producers, stdout, stderr string) { func initProducers(t *testing.T, producers producers, stdout, stderr string) {
_, err := producers.Stdout.Write([]byte(stdout)) _, err := producers.Stdout.Write([]byte(stdout))
require.NoError(t, err) assert.NilError(t, err)
require.NoError(t, producers.Stdout.Close()) assert.NilError(t, producers.Stdout.Close())
_, err = producers.Stderr.Write([]byte(stderr)) _, err = producers.Stderr.Write([]byte(stderr))
require.NoError(t, err) assert.NilError(t, err)
require.NoError(t, producers.Stderr.Close()) assert.NilError(t, producers.Stderr.Close())
} }

View File

@ -8,9 +8,9 @@ import (
"testing" "testing"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
type copySource struct { type copySource struct {
@ -63,9 +63,9 @@ func TestCopy(t *testing.T) {
testcase.source.size, testcase.source.size,
testcase.source.digest) testcase.source.digest)
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, testcase.source.digest, testcase.writer.commitedDigest) assert.Check(t, is.Equal(testcase.source.digest, testcase.writer.commitedDigest))
assert.Equal(t, testcase.expected, testcase.writer.String()) assert.Check(t, is.Equal(testcase.expected, testcase.writer.String()))
}) })
} }
} }

View File

@ -21,8 +21,8 @@ import (
"github.com/containerd/containerd/content" "github.com/containerd/containerd/content"
"github.com/containerd/containerd/content/testsuite" "github.com/containerd/containerd/content/testsuite"
"github.com/containerd/containerd/testutil" "github.com/containerd/containerd/testutil"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/stretchr/testify/require"
) )
type memoryLabelStore struct { type memoryLabelStore struct {
@ -339,11 +339,11 @@ func checkWrite(ctx context.Context, t checker, cs content.Store, dgst digest.Di
func TestWriterTruncateRecoversFromIncompleteWrite(t *testing.T) { func TestWriterTruncateRecoversFromIncompleteWrite(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "test-local-content-store-recover") tmpdir, err := ioutil.TempDir("", "test-local-content-store-recover")
require.NoError(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpdir) defer os.RemoveAll(tmpdir)
cs, err := NewStore(tmpdir) cs, err := NewStore(tmpdir)
require.NoError(t, err) assert.NilError(t, err)
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
@ -354,24 +354,24 @@ func TestWriterTruncateRecoversFromIncompleteWrite(t *testing.T) {
setupIncompleteWrite(ctx, t, cs, ref, total) setupIncompleteWrite(ctx, t, cs, ref, total)
writer, err := cs.Writer(ctx, ref, total, "") writer, err := cs.Writer(ctx, ref, total, "")
require.NoError(t, err) assert.NilError(t, err)
require.NoError(t, writer.Truncate(0)) assert.NilError(t, writer.Truncate(0))
_, err = writer.Write(content) _, err = writer.Write(content)
require.NoError(t, err) assert.NilError(t, err)
dgst := digest.FromBytes(content) dgst := digest.FromBytes(content)
err = writer.Commit(ctx, total, dgst) err = writer.Commit(ctx, total, dgst)
require.NoError(t, err) assert.NilError(t, err)
} }
func setupIncompleteWrite(ctx context.Context, t *testing.T, cs content.Store, ref string, total int64) { func setupIncompleteWrite(ctx context.Context, t *testing.T, cs content.Store, ref string, total int64) {
writer, err := cs.Writer(ctx, ref, total, "") writer, err := cs.Writer(ctx, ref, total, "")
require.NoError(t, err) assert.NilError(t, err)
_, err = writer.Write([]byte("bad data")) _, err = writer.Write([]byte("bad data"))
require.NoError(t, err) assert.NilError(t, err)
require.NoError(t, writer.Close()) assert.NilError(t, writer.Close())
} }

View File

@ -16,9 +16,9 @@ import (
"github.com/containerd/containerd/content" "github.com/containerd/containerd/content"
"github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/testutil" "github.com/containerd/containerd/testutil"
"github.com/gotestyourself/gotestyourself/assert"
digest "github.com/opencontainers/go-digest" digest "github.com/opencontainers/go-digest"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/require"
) )
// ContentSuite runs a test suite on the content store given a factory function. // ContentSuite runs a test suite on the content store given a factory function.
@ -188,7 +188,7 @@ func checkResumeWriter(ctx context.Context, t *testing.T, cs content.Store) {
} }
checkStatus(t, w1, expected, dgstFirst, preStart, postStart, preUpdate, postUpdate) checkStatus(t, w1, expected, dgstFirst, preStart, postStart, preUpdate, postUpdate)
require.NoError(t, w1.Close(), "close first writer") assert.NilError(t, w1.Close(), "close first writer")
w2, err := cs.Writer(ctx, ref, 256, dgst) w2, err := cs.Writer(ctx, ref, 256, dgst)
if err != nil { if err != nil {
@ -212,7 +212,7 @@ func checkResumeWriter(ctx context.Context, t *testing.T, cs content.Store) {
} }
postCommit := time.Now() postCommit := time.Now()
require.NoError(t, w2.Close(), "close second writer") assert.NilError(t, w2.Close(), "close second writer")
info := content.Info{ info := content.Info{
Digest: dgst, Digest: dgst,
Size: 256, Size: 256,

View File

@ -7,7 +7,7 @@ import (
"time" "time"
"github.com/containerd/containerd/gc" "github.com/containerd/containerd/gc"
"github.com/stretchr/testify/require" "github.com/gotestyourself/gotestyourself/assert"
) )
func TestPauseThreshold(t *testing.T) { func TestPauseThreshold(t *testing.T) {
@ -123,7 +123,7 @@ func TestTrigger(t *testing.T) {
t.Fatalf("GC failed: %#v", err) t.Fatalf("GC failed: %#v", err)
} }
require.Equal(t, tc.d, stats.Elapsed()) assert.Equal(t, tc.d, stats.Elapsed())
if c := tc.runCount(); c != 1 { if c := tc.runCount(); c != 1 {
t.Fatalf("unexpected gc run count %d, expected 1", c) t.Fatalf("unexpected gc run count %d, expected 1", c)

View File

@ -3,9 +3,10 @@ package oci
import ( import (
"testing" "testing"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1" ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/stretchr/testify/assert"
) )
func TestNormalizeImageRef(t *testing.T) { func TestNormalizeImageRef(t *testing.T) {
@ -31,7 +32,7 @@ func TestNormalizeImageRef(t *testing.T) {
}, },
} { } {
normalized, err := normalizeImageRef(imageBaseName, test.input) normalized, err := normalizeImageRef(imageBaseName, test.input)
assert.NoError(t, err) assert.Check(t, is.NilError(err))
assert.Equal(t, test.expect, normalized) assert.Check(t, is.Equal(test.expect, normalized))
} }
} }

View File

@ -4,15 +4,16 @@ import (
"context" "context"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestLoggerContext(t *testing.T) { func TestLoggerContext(t *testing.T) {
ctx := context.Background() ctx := context.Background()
assert.Equal(t, GetLogger(ctx), L) // should be same as L variable assert.Check(t, is.DeepEqual(GetLogger(ctx), L)) // should be same as L variable
assert.Equal(t, G(ctx), GetLogger(ctx)) // these should be the same. assert.Check(t, is.DeepEqual(G(ctx), GetLogger(ctx))) // these should be the same.
ctx = WithLogger(ctx, G(ctx).WithField("test", "one")) ctx = WithLogger(ctx, G(ctx).WithField("test", "one"))
assert.Equal(t, GetLogger(ctx).Data["test"], "one") assert.Check(t, is.DeepEqual(GetLogger(ctx).Data["test"], "one"))
assert.Equal(t, G(ctx), GetLogger(ctx)) // these should be the same. assert.Check(t, is.DeepEqual(G(ctx), GetLogger(ctx))) // these should be the same.
} }

View File

@ -20,17 +20,15 @@ import (
"github.com/containerd/containerd/mount" "github.com/containerd/containerd/mount"
"github.com/containerd/containerd/testutil" "github.com/containerd/containerd/testutil"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
"github.com/stretchr/testify/require" is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func checkLookup(t *testing.T, fsType, mntPoint, dir string) { func checkLookup(t *testing.T, fsType, mntPoint, dir string) {
info, err := mount.Lookup(dir) info, err := mount.Lookup(dir)
if err != nil { assert.NilError(t, err)
t.Fatal(err) assert.Check(t, is.Equal(fsType, info.FSType))
} assert.Check(t, is.Equal(mntPoint, info.Mountpoint))
assert.Equal(t, fsType, info.FSType)
assert.Equal(t, mntPoint, info.Mountpoint)
} }
func testLookup(t *testing.T, fsType string) { func testLookup(t *testing.T, fsType string) {
@ -57,7 +55,7 @@ func testLookup(t *testing.T, fsType string) {
testutil.Unmount(t, mnt) testutil.Unmount(t, mnt)
cleanupDevice() cleanupDevice()
}() }()
assert.True(t, strings.HasPrefix(deviceName, "/dev/loop")) assert.Check(t, strings.HasPrefix(deviceName, "/dev/loop"))
checkLookup(t, fsType, mnt, mnt) checkLookup(t, fsType, mnt, mnt)
newMnt, err := ioutil.TempDir("", "containerd-mountinfo-test-newMnt") newMnt, err := ioutil.TempDir("", "containerd-mountinfo-test-newMnt")
@ -92,19 +90,19 @@ func TestLookupWithXFS(t *testing.T) {
func TestLookupWithOverlay(t *testing.T) { func TestLookupWithOverlay(t *testing.T) {
lower, err := ioutil.TempDir("", "containerd-mountinfo-test-lower") lower, err := ioutil.TempDir("", "containerd-mountinfo-test-lower")
require.NoError(t, err) assert.NilError(t, err)
defer os.RemoveAll(lower) defer os.RemoveAll(lower)
upper, err := ioutil.TempDir("", "containerd-mountinfo-test-upper") upper, err := ioutil.TempDir("", "containerd-mountinfo-test-upper")
require.NoError(t, err) assert.NilError(t, err)
defer os.RemoveAll(upper) defer os.RemoveAll(upper)
work, err := ioutil.TempDir("", "containerd-mountinfo-test-work") work, err := ioutil.TempDir("", "containerd-mountinfo-test-work")
require.NoError(t, err) assert.NilError(t, err)
defer os.RemoveAll(work) defer os.RemoveAll(work)
overlay, err := ioutil.TempDir("", "containerd-mountinfo-test-overlay") overlay, err := ioutil.TempDir("", "containerd-mountinfo-test-overlay")
require.NoError(t, err) assert.NilError(t, err)
defer os.RemoveAll(overlay) defer os.RemoveAll(overlay)
if out, err := exec.Command("mount", "-t", "overlay", "overlay", "-o", fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", if out, err := exec.Command("mount", "-t", "overlay", "overlay", "-o", fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s",
@ -116,11 +114,11 @@ func TestLookupWithOverlay(t *testing.T) {
testdir := filepath.Join(overlay, "testdir") testdir := filepath.Join(overlay, "testdir")
err = os.Mkdir(testdir, 0777) err = os.Mkdir(testdir, 0777)
require.NoError(t, err) assert.NilError(t, err)
testfile := filepath.Join(overlay, "testfile") testfile := filepath.Join(overlay, "testfile")
_, err = os.Create(testfile) _, err = os.Create(testfile)
require.NoError(t, err) assert.NilError(t, err)
checkLookup(t, "overlay", overlay, testdir) checkLookup(t, "overlay", overlay, testdir)
checkLookup(t, "overlay", overlay, testfile) checkLookup(t, "overlay", overlay, testfile)

View File

@ -4,7 +4,8 @@ import (
"testing" "testing"
"github.com/containerd/containerd/reference" "github.com/containerd/containerd/reference"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestRepositoryScope(t *testing.T) { func TestRepositoryScope(t *testing.T) {
@ -32,7 +33,7 @@ func TestRepositoryScope(t *testing.T) {
} }
for _, x := range testCases { for _, x := range testCases {
actual, err := repositoryScope(x.refspec, x.push) actual, err := repositoryScope(x.refspec, x.push)
assert.NoError(t, err) assert.Check(t, is.NilError(err))
assert.Equal(t, x.expected, actual) assert.Check(t, is.Equal(x.expected, actual))
} }
} }

View File

@ -3,7 +3,8 @@ package server
import ( import (
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -13,5 +14,5 @@ func TestNewErrorsWithSamePathForRootAndState(t *testing.T) {
Root: path, Root: path,
State: path, State: path,
}) })
assert.EqualError(t, err, "root and state must be different paths") assert.Check(t, is.Error(err, "root and state must be different paths"))
} }

View File

@ -10,8 +10,9 @@ import (
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/snapshots" "github.com/containerd/containerd/snapshots"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
type testFunc func(context.Context, *testing.T, *MetaStore) type testFunc func(context.Context, *testing.T, *MetaStore)
@ -242,7 +243,7 @@ func testGetInfo(ctx context.Context, t *testing.T, ms *MetaStore) {
// TODO: Check timestamp range // TODO: Check timestamp range
info.Created = time.Time{} info.Created = time.Time{}
info.Updated = time.Time{} info.Updated = time.Time{}
assert.Equal(t, expected, info) assert.Check(t, is.DeepEqual(expected, info))
} }
} }
@ -266,7 +267,7 @@ func testWalk(ctx context.Context, t *testing.T, ms *MetaStore) {
if err != nil { if err != nil {
t.Fatalf("Walk failed: %+v", err) t.Fatalf("Walk failed: %+v", err)
} }
assert.Equal(t, baseInfo, found) assert.Check(t, is.DeepEqual(baseInfo, found))
} }
func testGetSnapshot(ctx context.Context, t *testing.T, ms *MetaStore) { func testGetSnapshot(ctx context.Context, t *testing.T, ms *MetaStore) {
@ -318,7 +319,7 @@ func testGetSnapshot(ctx context.Context, t *testing.T, ms *MetaStore) {
if err != nil { if err != nil {
t.Fatalf("Failed to get active: %+v", err) t.Fatalf("Failed to get active: %+v", err)
} }
assert.Equal(t, expected, s) assert.Check(t, is.DeepEqual(expected, s))
} }
} }

View File

@ -16,7 +16,8 @@ import (
"github.com/containerd/containerd/snapshots" "github.com/containerd/containerd/snapshots"
"github.com/containerd/containerd/testutil" "github.com/containerd/containerd/testutil"
"github.com/containerd/continuity/fs/fstest" "github.com/containerd/continuity/fs/fstest"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
// SnapshotterSuite runs a test suite on the snapshotter given a factory function. // SnapshotterSuite runs a test suite on the snapshotter given a factory function.
@ -145,8 +146,8 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
t.Fatalf("failure reason: %+v", err) t.Fatalf("failure reason: %+v", err)
} }
assert.Equal(t, "", si.Parent) assert.Check(t, is.Equal("", si.Parent))
assert.Equal(t, snapshots.KindCommitted, si.Kind) assert.Check(t, is.Equal(snapshots.KindCommitted, si.Kind))
_, err = snapshotter.Stat(ctx, preparing) _, err = snapshotter.Stat(ctx, preparing)
if err == nil { if err == nil {
@ -180,8 +181,8 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
t.Fatal(err) t.Fatal(err)
} }
assert.Equal(t, committed, ni.Parent) assert.Check(t, is.Equal(committed, ni.Parent))
assert.Equal(t, snapshots.KindActive, ni.Kind) assert.Check(t, is.Equal(snapshots.KindActive, ni.Kind))
nextCommitted := filepath.Join(work, "committed-next") nextCommitted := filepath.Join(work, "committed-next")
if err := snapshotter.Commit(ctx, nextCommitted, next, opt); err != nil { if err := snapshotter.Commit(ctx, nextCommitted, next, opt); err != nil {
@ -193,8 +194,8 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
t.Fatalf("failure reason: %+v", err) t.Fatalf("failure reason: %+v", err)
} }
assert.Equal(t, committed, si2.Parent) assert.Check(t, is.Equal(committed, si2.Parent))
assert.Equal(t, snapshots.KindCommitted, si2.Kind) assert.Check(t, is.Equal(snapshots.KindCommitted, si2.Kind))
_, err = snapshotter.Stat(ctx, next) _, err = snapshotter.Stat(ctx, next)
if err == nil { if err == nil {
@ -206,10 +207,10 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
si2.Name: si2, si2.Name: si2,
} }
walked := map[string]snapshots.Info{} // walk is not ordered walked := map[string]snapshots.Info{} // walk is not ordered
assert.NoError(t, snapshotter.Walk(ctx, func(ctx context.Context, si snapshots.Info) error { assert.Check(t, is.NilError(snapshotter.Walk(ctx, func(ctx context.Context, si snapshots.Info) error {
walked[si.Name] = si walked[si.Name] = si
return nil return nil
})) })))
for ek, ev := range expected { for ek, ev := range expected {
av, ok := walked[ek] av, ok := walked[ek]
@ -217,7 +218,7 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
t.Errorf("Missing stat for %v", ek) t.Errorf("Missing stat for %v", ek)
continue continue
} }
assert.Equal(t, ev, av) assert.Check(t, is.DeepEqual(ev, av))
} }
nextnext := filepath.Join(work, "nextnextlayer") nextnext := filepath.Join(work, "nextnextlayer")
@ -240,10 +241,10 @@ func checkSnapshotterBasic(ctx context.Context, t *testing.T, snapshotter snapsh
} }
testutil.Unmount(t, nextnext) testutil.Unmount(t, nextnext)
assert.NoError(t, snapshotter.Remove(ctx, nextnext)) assert.Check(t, is.NilError(snapshotter.Remove(ctx, nextnext)))
assert.Error(t, snapshotter.Remove(ctx, committed)) assert.Check(t, is.ErrorContains(snapshotter.Remove(ctx, committed), ""))
assert.NoError(t, snapshotter.Remove(ctx, nextCommitted)) assert.Check(t, is.NilError(snapshotter.Remove(ctx, nextCommitted)))
assert.NoError(t, snapshotter.Remove(ctx, committed)) assert.Check(t, is.NilError(snapshotter.Remove(ctx, committed)))
} }
// Create a New Layer on top of base layer with Prepare, Stat on new layer, should return Active layer. // Create a New Layer on top of base layer with Prepare, Stat on new layer, should return Active layer.
@ -275,9 +276,9 @@ func checkSnapshotterStatActive(ctx context.Context, t *testing.T, snapshotter s
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
assert.Equal(t, si.Name, preparing) assert.Check(t, is.Equal(si.Name, preparing))
assert.Equal(t, snapshots.KindActive, si.Kind) assert.Check(t, is.Equal(snapshots.KindActive, si.Kind))
assert.Equal(t, "", si.Parent) assert.Check(t, is.Equal("", si.Parent))
} }
// Commit a New Layer on top of base layer with Prepare & Commit , Stat on new layer, should return Committed layer. // Commit a New Layer on top of base layer with Prepare & Commit , Stat on new layer, should return Committed layer.
@ -314,9 +315,9 @@ func checkSnapshotterStatCommitted(ctx context.Context, t *testing.T, snapshotte
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
assert.Equal(t, si.Name, committed) assert.Check(t, is.Equal(si.Name, committed))
assert.Equal(t, snapshots.KindCommitted, si.Kind) assert.Check(t, is.Equal(snapshots.KindCommitted, si.Kind))
assert.Equal(t, "", si.Parent) assert.Check(t, is.Equal("", si.Parent))
} }
@ -389,9 +390,9 @@ func checkSnapshotterTransitivity(ctx context.Context, t *testing.T, snapshotter
} }
// Test the transivity // Test the transivity
assert.Equal(t, "", siA.Parent) assert.Check(t, is.Equal("", siA.Parent))
assert.Equal(t, snapA, siB.Parent) assert.Check(t, is.Equal(snapA, siB.Parent))
assert.Equal(t, "", siParentB.Parent) assert.Check(t, is.Equal("", siParentB.Parent))
} }
@ -422,7 +423,7 @@ func checkSnapshotterPrepareView(ctx context.Context, t *testing.T, snapshotter
_, err = snapshotter.View(ctx, newLayer, snapA, opt) _, err = snapshotter.View(ctx, newLayer, snapA, opt)
//must be err != nil //must be err != nil
assert.NotNil(t, err) assert.Check(t, err != nil)
// Two Prepare with same key // Two Prepare with same key
prepLayer := filepath.Join(work, "prepLayer") prepLayer := filepath.Join(work, "prepLayer")
@ -437,7 +438,7 @@ func checkSnapshotterPrepareView(ctx context.Context, t *testing.T, snapshotter
_, err = snapshotter.Prepare(ctx, prepLayer, snapA, opt) _, err = snapshotter.Prepare(ctx, prepLayer, snapA, opt)
//must be err != nil //must be err != nil
assert.NotNil(t, err) assert.Check(t, err != nil)
// Two View with same key // Two View with same key
viewLayer := filepath.Join(work, "viewLayer") viewLayer := filepath.Join(work, "viewLayer")
@ -452,7 +453,7 @@ func checkSnapshotterPrepareView(ctx context.Context, t *testing.T, snapshotter
_, err = snapshotter.View(ctx, viewLayer, snapA, opt) _, err = snapshotter.View(ctx, viewLayer, snapA, opt)
//must be err != nil //must be err != nil
assert.NotNil(t, err) assert.Check(t, err != nil)
} }
@ -781,8 +782,8 @@ func checkSnapshotterViewReadonly(ctx context.Context, t *testing.T, snapshotter
t.Fatalf("write to %q should fail (EROFS) but did not fail", testfile) t.Fatalf("write to %q should fail (EROFS) but did not fail", testfile)
} }
testutil.Unmount(t, viewMountPoint) testutil.Unmount(t, viewMountPoint)
assert.NoError(t, snapshotter.Remove(ctx, view)) assert.Check(t, is.NilError(snapshotter.Remove(ctx, view)))
assert.NoError(t, snapshotter.Remove(ctx, committed)) assert.Check(t, is.NilError(snapshotter.Remove(ctx, committed)))
} }
// Move files from base layer to new location in intermediate layer. // Move files from base layer to new location in intermediate layer.

View File

@ -8,7 +8,8 @@ import (
"testing" "testing"
"github.com/containerd/containerd/mount" "github.com/containerd/containerd/mount"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
// Unmount unmounts a given mountPoint and sets t.Error if it fails // Unmount unmounts a given mountPoint and sets t.Error if it fails
@ -26,7 +27,7 @@ func RequiresRoot(t testing.TB) {
t.Skip("skipping test that requires root") t.Skip("skipping test that requires root")
return return
} }
assert.Equal(t, 0, os.Getuid(), "This test must be run as root.") assert.Check(t, is.Equal(0, os.Getuid()), "This test must be run as root.")
} }
// RequiresRootM is similar to RequiresRoot but intended to be called from *testing.M. // RequiresRootM is similar to RequiresRoot but intended to be called from *testing.M.