contenthash: use require in all tests

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
docker-18.09
Tonis Tiigi 2018-09-21 11:19:15 -07:00
parent 39404586a5
commit a93a96b0e3
1 changed files with 70 additions and 71 deletions

View File

@ -18,7 +18,6 @@ import (
"github.com/moby/buildkit/snapshot"
digest "github.com/opencontainers/go-digest"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tonistiigi/fsutil"
)
@ -55,53 +54,53 @@ func TestChecksumBasicFile(t *testing.T) {
// phase but consistency is
cc, err := newCacheContext(ref.Metadata())
assert.NoError(t, err)
require.NoError(t, err)
_, err = cc.Checksum(context.TODO(), ref, "nosuch")
assert.Error(t, err)
require.Error(t, err)
dgst, err := cc.Checksum(context.TODO(), ref, "foo")
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, dgstFileData0, dgst)
require.Equal(t, dgstFileData0, dgst)
// second file returns different hash
dgst, err = cc.Checksum(context.TODO(), ref, "bar")
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, digest.Digest("sha256:c2b5e234f5f38fc5864da7def04782f82501a40d46192e4207d5b3f0c3c4732b"), dgst)
require.Equal(t, digest.Digest("sha256:c2b5e234f5f38fc5864da7def04782f82501a40d46192e4207d5b3f0c3c4732b"), dgst)
// same file inside a directory
dgst, err = cc.Checksum(context.TODO(), ref, "d0/abc")
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, dgstFileData0, dgst)
require.Equal(t, dgstFileData0, dgst)
// repeat because codepath is different
dgst, err = cc.Checksum(context.TODO(), ref, "d0/abc")
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, dgstFileData0, dgst)
require.Equal(t, dgstFileData0, dgst)
// symlink to the same file is followed, returns same hash
dgst, err = cc.Checksum(context.TODO(), ref, "d0/def")
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, dgstFileData0, dgst)
require.Equal(t, dgstFileData0, dgst)
_, err = cc.Checksum(context.TODO(), ref, "d0/ghi")
assert.Error(t, err)
assert.Equal(t, errNotFound, errors.Cause(err))
require.Error(t, err)
require.Equal(t, errNotFound, errors.Cause(err))
dgst, err = cc.Checksum(context.TODO(), ref, "/")
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, digest.Digest("sha256:427c9cf9ae98c0f81fb57a3076b965c7c149b6b0a85625ad4e884236649a42c6"), dgst)
require.Equal(t, digest.Digest("sha256:427c9cf9ae98c0f81fb57a3076b965c7c149b6b0a85625ad4e884236649a42c6"), dgst)
dgst, err = cc.Checksum(context.TODO(), ref, "d0")
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, dgstDirD0, dgst)
require.Equal(t, dgstDirD0, dgst)
err = ref.Release(context.TODO())
require.NoError(t, err)
@ -116,12 +115,12 @@ func TestChecksumBasicFile(t *testing.T) {
ref = createRef(t, cm, ch)
cc, err = newCacheContext(ref.Metadata())
assert.NoError(t, err)
require.NoError(t, err)
dgst, err = cc.Checksum(context.TODO(), ref, "/")
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, dgstDirD0, dgst)
require.Equal(t, dgstDirD0, dgst)
err = ref.Release(context.TODO())
require.NoError(t, err)
@ -135,13 +134,13 @@ func TestChecksumBasicFile(t *testing.T) {
ref = createRef(t, cm, ch)
cc, err = newCacheContext(ref.Metadata())
assert.NoError(t, err)
require.NoError(t, err)
dgst, err = cc.Checksum(context.TODO(), ref, "/")
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, dgstDirD0Modified, dgst)
assert.NotEqual(t, dgstDirD0, dgst)
require.Equal(t, dgstDirD0Modified, dgst)
require.NotEqual(t, dgstDirD0, dgst)
err = ref.Release(context.TODO())
require.NoError(t, err)
@ -161,19 +160,19 @@ func TestChecksumBasicFile(t *testing.T) {
ref = createRef(t, cm, ch)
cc, err = newCacheContext(ref.Metadata())
assert.NoError(t, err)
require.NoError(t, err)
dgst, err = cc.Checksum(context.TODO(), ref, "abc/aa/foo")
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, digest.Digest("sha256:1c67653c3cf95b12a0014e2c4cd1d776b474b3218aee54155d6ae27b9b999c54"), dgst)
assert.NotEqual(t, dgstDirD0, dgst)
require.Equal(t, digest.Digest("sha256:1c67653c3cf95b12a0014e2c4cd1d776b474b3218aee54155d6ae27b9b999c54"), dgst)
require.NotEqual(t, dgstDirD0, dgst)
// this will force rescan
dgst, err = cc.Checksum(context.TODO(), ref, "d0")
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, dgstDirD0, dgst)
require.Equal(t, dgstDirD0, dgst)
err = ref.Release(context.TODO())
require.NoError(t, err)
@ -205,53 +204,53 @@ func TestHandleChange(t *testing.T) {
// phase but consistency is
cc, err := newCacheContext(ref.Metadata())
assert.NoError(t, err)
require.NoError(t, err)
err = emit(cc.HandleChange, changeStream(ch))
assert.NoError(t, err)
require.NoError(t, err)
dgstFoo, err := cc.Checksum(context.TODO(), ref, "foo")
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, dgstFileData0, dgstFoo)
require.Equal(t, dgstFileData0, dgstFoo)
// symlink to the same file is followed, returns same hash
dgst, err := cc.Checksum(context.TODO(), ref, "d0/def")
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, dgstFoo, dgst)
require.Equal(t, dgstFoo, dgst)
// symlink to the same file is followed, returns same hash
dgst, err = cc.Checksum(context.TODO(), ref, "d0")
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, dgstDirD0, dgst)
require.Equal(t, dgstDirD0, dgst)
ch = []string{
"DEL d0/ghi file",
}
err = emit(cc.HandleChange, changeStream(ch))
assert.NoError(t, err)
require.NoError(t, err)
dgst, err = cc.Checksum(context.TODO(), ref, "d0")
assert.NoError(t, err)
assert.Equal(t, dgstDirD0Modified, dgst)
require.NoError(t, err)
require.Equal(t, dgstDirD0Modified, dgst)
ch = []string{
"DEL d0 dir",
}
err = emit(cc.HandleChange, changeStream(ch))
assert.NoError(t, err)
require.NoError(t, err)
_, err = cc.Checksum(context.TODO(), ref, "d0")
assert.Error(t, err)
assert.Equal(t, errNotFound, errors.Cause(err))
require.Error(t, err)
require.Equal(t, errNotFound, errors.Cause(err))
_, err = cc.Checksum(context.TODO(), ref, "d0/abc")
assert.Error(t, err)
assert.Equal(t, errNotFound, errors.Cause(err))
require.Error(t, err)
require.Equal(t, errNotFound, errors.Cause(err))
err = ref.Release(context.TODO())
require.NoError(t, err)
@ -281,13 +280,13 @@ func TestHandleRecursiveDir(t *testing.T) {
ref := createRef(t, cm, nil)
cc, err := newCacheContext(ref.Metadata())
assert.NoError(t, err)
require.NoError(t, err)
err = emit(cc.HandleChange, changeStream(ch))
assert.NoError(t, err)
require.NoError(t, err)
dgst, err := cc.Checksum(context.TODO(), ref, "d0/foo/bar")
assert.NoError(t, err)
require.NoError(t, err)
ch = []string{
"DEL d0 dir",
@ -296,14 +295,14 @@ func TestHandleRecursiveDir(t *testing.T) {
}
err = emit(cc.HandleChange, changeStream(ch))
assert.NoError(t, err)
require.NoError(t, err)
dgst2, err := cc.Checksum(context.TODO(), ref, "d1")
assert.NoError(t, err)
assert.Equal(t, dgst2, dgst)
require.NoError(t, err)
require.Equal(t, dgst2, dgst)
_, err = cc.Checksum(context.TODO(), ref, "")
assert.NoError(t, err)
require.NoError(t, err)
}
func TestChecksumUnorderedFiles(t *testing.T) {
@ -328,15 +327,15 @@ func TestChecksumUnorderedFiles(t *testing.T) {
ref := createRef(t, cm, nil)
cc, err := newCacheContext(ref.Metadata())
assert.NoError(t, err)
require.NoError(t, err)
err = emit(cc.HandleChange, changeStream(ch))
assert.NoError(t, err)
require.NoError(t, err)
dgst, err := cc.Checksum(context.TODO(), ref, "d0")
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, dgst, digest.Digest("sha256:14276c302c940a80f82ca5477bf766c98a24702d6a9948ee71bb277cdad3ae05"))
require.Equal(t, dgst, digest.Digest("sha256:14276c302c940a80f82ca5477bf766c98a24702d6a9948ee71bb277cdad3ae05"))
// check regression from earier version that didn't track some files
ch = []string{
@ -348,15 +347,15 @@ func TestChecksumUnorderedFiles(t *testing.T) {
ref = createRef(t, cm, nil)
cc, err = newCacheContext(ref.Metadata())
assert.NoError(t, err)
require.NoError(t, err)
err = emit(cc.HandleChange, changeStream(ch))
assert.NoError(t, err)
require.NoError(t, err)
dgst2, err := cc.Checksum(context.TODO(), ref, "d0")
assert.NoError(t, err)
require.NoError(t, err)
assert.NotEqual(t, dgst, dgst2)
require.NotEqual(t, dgst, dgst2)
}
func TestPersistence(t *testing.T) {
@ -383,18 +382,18 @@ func TestPersistence(t *testing.T) {
id := ref.ID()
dgst, err := Checksum(context.TODO(), ref, "foo")
assert.NoError(t, err)
assert.Equal(t, dgstFileData0, dgst)
require.NoError(t, err)
require.Equal(t, dgstFileData0, dgst)
err = ref.Release(context.TODO())
require.NoError(t, err)
ref, err = cm.Get(context.TODO(), id)
assert.NoError(t, err)
require.NoError(t, err)
dgst, err = Checksum(context.TODO(), ref, "foo")
assert.NoError(t, err)
assert.Equal(t, dgstFileData0, dgst)
require.NoError(t, err)
require.Equal(t, dgstFileData0, dgst)
err = ref.Release(context.TODO())
require.NoError(t, err)
@ -408,11 +407,11 @@ func TestPersistence(t *testing.T) {
defer cm.Close()
ref, err = cm.Get(context.TODO(), id)
assert.NoError(t, err)
require.NoError(t, err)
dgst, err = Checksum(context.TODO(), ref, "foo")
assert.NoError(t, err)
assert.Equal(t, dgstFileData0, dgst)
require.NoError(t, err)
require.Equal(t, dgstFileData0, dgst)
}
func createRef(t *testing.T, cm cache.Manager, files []string) cache.ImmutableRef {