1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Post migration assertion fixes

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2017-12-22 16:30:49 -05:00
parent 6be0f70983
commit c9e52bd0da
23 changed files with 184 additions and 136 deletions

View file

@ -2,6 +2,7 @@ package dockerfile // import "github.com/docker/docker/builder/dockerfile"
import ( import (
"bytes" "bytes"
"strings"
"testing" "testing"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
@ -78,9 +79,9 @@ func TestWarnOnUnusedBuildArgs(t *testing.T) {
buffer := new(bytes.Buffer) buffer := new(bytes.Buffer)
buildArgs.WarnOnUnusedBuildArgs(buffer) buildArgs.WarnOnUnusedBuildArgs(buffer)
out := buffer.String() out := buffer.String()
assert.NotContains(t, out, "ThisArgIsUsed") assert.Assert(t, !strings.Contains(out, "ThisArgIsUsed"), out)
assert.NotContains(t, out, "HTTPS_PROXY") assert.Assert(t, !strings.Contains(out, "HTTPS_PROXY"), out)
assert.NotContains(t, out, "HTTP_PROXY") assert.Assert(t, !strings.Contains(out, "HTTP_PROXY"), out)
assert.Check(t, is.Contains(out, "ThisArgIsNotUsed")) assert.Check(t, is.Contains(out, "ThisArgIsNotUsed"))
} }

View file

@ -3,6 +3,7 @@ package parser // import "github.com/docker/docker/builder/dockerfile/parser"
import ( import (
"testing" "testing"
"github.com/google/go-cmp/cmp"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp" is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
@ -16,9 +17,11 @@ func TestParseNameValOldFormat(t *testing.T) {
Value: "foo", Value: "foo",
Next: &Node{Value: "bar"}, Next: &Node{Value: "bar"},
} }
assert.Check(t, is.DeepEqual(expected, node)) assert.DeepEqual(t, expected, node, cmpNodeOpt)
} }
var cmpNodeOpt = cmp.AllowUnexported(Node{})
func TestParseNameValNewFormat(t *testing.T) { func TestParseNameValNewFormat(t *testing.T) {
directive := Directive{} directive := Directive{}
node, err := parseNameVal("foo=bar thing=star", "LABEL", &directive) node, err := parseNameVal("foo=bar thing=star", "LABEL", &directive)
@ -36,7 +39,7 @@ func TestParseNameValNewFormat(t *testing.T) {
}, },
}, },
} }
assert.Check(t, is.DeepEqual(expected, node)) assert.DeepEqual(t, expected, node, cmpNodeOpt)
} }
func TestNodeFromLabels(t *testing.T) { func TestNodeFromLabels(t *testing.T) {
@ -62,8 +65,7 @@ func TestNodeFromLabels(t *testing.T) {
} }
node := NodeFromLabels(labels) node := NodeFromLabels(labels)
assert.Check(t, is.DeepEqual(expected, node)) assert.DeepEqual(t, expected, node, cmpNodeOpt)
} }
func TestParseNameValWithoutVal(t *testing.T) { func TestParseNameValWithoutVal(t *testing.T) {

View file

@ -13,6 +13,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/google/go-cmp/cmp"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp" is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
@ -20,35 +21,31 @@ import (
func TestParseRemoteURL(t *testing.T) { func TestParseRemoteURL(t *testing.T) {
dir, err := parseRemoteURL("git://github.com/user/repo.git") dir, err := parseRemoteURL("git://github.com/user/repo.git")
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, len(dir) != 0) assert.Check(t, is.DeepEqual(gitRepo{"git://github.com/user/repo.git", "master", ""}, dir, cmpGitRepoOpt))
assert.Check(t, is.DeepEqual(gitRepo{"git://github.com/user/repo.git", "master", ""}, dir))
dir, err = parseRemoteURL("git://github.com/user/repo.git#mybranch:mydir/mysubdir/") dir, err = parseRemoteURL("git://github.com/user/repo.git#mybranch:mydir/mysubdir/")
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, len(dir) != 0) assert.Check(t, is.DeepEqual(gitRepo{"git://github.com/user/repo.git", "mybranch", "mydir/mysubdir/"}, dir, cmpGitRepoOpt))
assert.Check(t, is.DeepEqual(gitRepo{"git://github.com/user/repo.git", "mybranch", "mydir/mysubdir/"}, dir))
dir, err = parseRemoteURL("https://github.com/user/repo.git") dir, err = parseRemoteURL("https://github.com/user/repo.git")
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, len(dir) != 0) assert.Check(t, is.DeepEqual(gitRepo{"https://github.com/user/repo.git", "master", ""}, dir, cmpGitRepoOpt))
assert.Check(t, is.DeepEqual(gitRepo{"https://github.com/user/repo.git", "master", ""}, dir))
dir, err = parseRemoteURL("https://github.com/user/repo.git#mybranch:mydir/mysubdir/") dir, err = parseRemoteURL("https://github.com/user/repo.git#mybranch:mydir/mysubdir/")
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, len(dir) != 0) assert.Check(t, is.DeepEqual(gitRepo{"https://github.com/user/repo.git", "mybranch", "mydir/mysubdir/"}, dir, cmpGitRepoOpt))
assert.Check(t, is.DeepEqual(gitRepo{"https://github.com/user/repo.git", "mybranch", "mydir/mysubdir/"}, dir))
dir, err = parseRemoteURL("git@github.com:user/repo.git") dir, err = parseRemoteURL("git@github.com:user/repo.git")
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, len(dir) != 0) assert.Check(t, is.DeepEqual(gitRepo{"git@github.com:user/repo.git", "master", ""}, dir, cmpGitRepoOpt))
assert.Check(t, is.DeepEqual(gitRepo{"git@github.com:user/repo.git", "master", ""}, dir))
dir, err = parseRemoteURL("git@github.com:user/repo.git#mybranch:mydir/mysubdir/") dir, err = parseRemoteURL("git@github.com:user/repo.git#mybranch:mydir/mysubdir/")
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, len(dir) != 0) assert.Check(t, is.DeepEqual(gitRepo{"git@github.com:user/repo.git", "mybranch", "mydir/mysubdir/"}, dir, cmpGitRepoOpt))
assert.Check(t, is.DeepEqual(gitRepo{"git@github.com:user/repo.git", "mybranch", "mydir/mysubdir/"}, dir))
} }
var cmpGitRepoOpt = cmp.AllowUnexported(gitRepo{})
func TestCloneArgsSmartHttp(t *testing.T) { func TestCloneArgsSmartHttp(t *testing.T) {
mux := http.NewServeMux() mux := http.NewServeMux()
server := httptest.NewServer(mux) server := httptest.NewServer(mux)

View file

@ -89,8 +89,7 @@ func TestNewEnvClient(t *testing.T) {
env.PatchAll(t, c.envs) env.PatchAll(t, c.envs)
apiclient, err := NewEnvClient() apiclient, err := NewEnvClient()
if c.expectedError != "" { if c.expectedError != "" {
assert.Check(t, is.ErrorContains(err, ""), c.doc) assert.Check(t, is.Error(err, c.expectedError), c.doc)
assert.Check(t, is.Equal(c.expectedError, err.Error()), c.doc)
} else { } else {
assert.Check(t, err, c.doc) assert.Check(t, err, c.doc)
version := apiclient.ClientVersion() version := apiclient.ClientVersion()
@ -100,7 +99,7 @@ func TestNewEnvClient(t *testing.T) {
if c.envs["DOCKER_TLS_VERIFY"] != "" { if c.envs["DOCKER_TLS_VERIFY"] != "" {
// pedantic checking that this is handled correctly // pedantic checking that this is handled correctly
tr := apiclient.client.Transport.(*http.Transport) tr := apiclient.client.Transport.(*http.Transport)
assert.Check(t, tr.TLSClientConfig != nil, c.doc) assert.Assert(t, tr.TLSClientConfig != nil, c.doc)
assert.Check(t, is.Equal(tr.TLSClientConfig.InsecureSkipVerify, false), c.doc) assert.Check(t, is.Equal(tr.TLSClientConfig.InsecureSkipVerify, false), c.doc)
} }
} }
@ -298,7 +297,7 @@ func TestClientRedirect(t *testing.T) {
cases := []struct { cases := []struct {
httpMethod string httpMethod string
expectedErr error expectedErr *url.Error
statusCode int statusCode int
}{ }{
{http.MethodGet, nil, 301}, {http.MethodGet, nil, 301},
@ -311,7 +310,13 @@ func TestClientRedirect(t *testing.T) {
req, err := http.NewRequest(tc.httpMethod, "/redirectme", nil) req, err := http.NewRequest(tc.httpMethod, "/redirectme", nil)
assert.Check(t, err) assert.Check(t, err)
resp, err := client.Do(req) resp, err := client.Do(req)
assert.Check(t, is.DeepEqual(tc.expectedErr, err))
assert.Check(t, is.Equal(tc.statusCode, resp.StatusCode)) assert.Check(t, is.Equal(tc.statusCode, resp.StatusCode))
if tc.expectedErr == nil {
assert.Check(t, is.Nil(err))
} else {
urlError, ok := err.(*url.Error)
assert.Assert(t, ok, "%T is not *url.Error", err)
assert.Check(t, is.Equal(*tc.expectedErr, *urlError))
}
} }
} }

View file

@ -15,7 +15,7 @@ import (
"github.com/docker/docker/daemon/graphdriver" "github.com/docker/docker/daemon/graphdriver"
"github.com/docker/docker/daemon/graphdriver/quota" "github.com/docker/docker/daemon/graphdriver/quota"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"github.com/docker/go-units" units "github.com/docker/go-units"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp" is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"

View file

@ -148,5 +148,5 @@ func testRetrieveQuota(t *testing.T, ctrl *Control, homeDir, testDir, testSubDir
var q Quota var q Quota
assert.NilError(t, ctrl.GetQuota(testSubDir, &q)) assert.NilError(t, ctrl.GetQuota(testSubDir, &q))
assert.Check(t, is.Equal(testQuotaSize, q.Size)) assert.Check(t, is.Equal(uint64(testQuotaSize), q.Size))
} }

View file

@ -121,7 +121,7 @@ func TestAdapterReadLogs(t *testing.T) {
} }
lr, ok := l.(LogReader) lr, ok := l.(LogReader)
assert.Check(t, ok != nil) assert.Check(t, ok, "Logger does not implement LogReader")
lw := lr.ReadLogs(ReadConfig{}) lw := lr.ReadLogs(ReadConfig{})
@ -158,7 +158,7 @@ func TestAdapterReadLogs(t *testing.T) {
select { select {
case msg, ok := <-lw.Msg: case msg, ok := <-lw.Msg:
assert.Check(t, ok != nil, "message channel unexpectedly closed") assert.Check(t, ok, "message channel unexpectedly closed")
testMessageEqual(t, &x, msg) testMessageEqual(t, &x, msg)
case <-time.After(10 * time.Second): case <-time.After(10 * time.Second):
t.Fatal("timeout reading logs") t.Fatal("timeout reading logs")

View file

@ -3,6 +3,7 @@ package jsonlog // import "github.com/docker/docker/daemon/logger/jsonfilelog/js
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt"
"regexp" "regexp"
"testing" "testing"
"time" "time"
@ -35,7 +36,16 @@ func TestJSONLogsMarshalJSONBuf(t *testing.T) {
var buf bytes.Buffer var buf bytes.Buffer
err := jsonLog.MarshalJSONBuf(&buf) err := jsonLog.MarshalJSONBuf(&buf)
assert.NilError(t, err) assert.NilError(t, err)
assert.Regexp(t, regexp.MustCompile(expression), buf.String())
assert.Check(t, json.Unmarshal(buf.Bytes(), &map[string]interface{}{})) assert.Assert(t, regexP(buf.String(), expression))
assert.NilError(t, json.Unmarshal(buf.Bytes(), &map[string]interface{}{}))
}
}
func regexP(value string, pattern string) func() (bool, string) {
return func() (bool, string) {
re := regexp.MustCompile(pattern)
msg := fmt.Sprintf("%q did not match pattern %q", value, pattern)
return re.MatchString(value), msg
} }
} }

View file

@ -9,6 +9,7 @@ import (
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/layer" "github.com/docker/docker/layer"
"github.com/google/go-cmp/cmp"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp" is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
@ -119,6 +120,6 @@ func TestNewChildImageFromImageWithRootFS(t *testing.T) {
assert.Check(t, is.Len(newImage.History, 2)) assert.Check(t, is.Len(newImage.History, 2))
assert.Check(t, is.Equal(childConfig.Comment, newImage.History[1].Comment)) assert.Check(t, is.Equal(childConfig.Comment, newImage.History[1].Comment))
// RootFS should be copied not mutated assert.Check(t, !cmp.Equal(parent.RootFS.DiffIDs, newImage.RootFS.DiffIDs),
assert.Check(t, parent.RootFS.DiffIDs != newImage.RootFS.DiffIDs) "RootFS should be copied not mutated")
} }

View file

@ -5,10 +5,9 @@ import (
"runtime" "runtime"
"testing" "testing"
"github.com/docker/docker/internal/testutil"
"github.com/docker/docker/layer" "github.com/docker/docker/layer"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
) )
@ -17,57 +16,57 @@ func TestRestore(t *testing.T) {
defer cleanup() defer cleanup()
id1, err := fs.Set([]byte(`{"comment": "abc", "rootfs": {"type": "layers"}}`)) id1, err := fs.Set([]byte(`{"comment": "abc", "rootfs": {"type": "layers"}}`))
assert.Check(t, err) assert.NilError(t, err)
_, err = fs.Set([]byte(`invalid`)) _, err = fs.Set([]byte(`invalid`))
assert.Check(t, err) assert.NilError(t, err)
id2, err := fs.Set([]byte(`{"comment": "def", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`)) id2, err := fs.Set([]byte(`{"comment": "def", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`))
assert.Check(t, err) assert.NilError(t, err)
err = fs.SetMetadata(id2, "parent", []byte(id1)) err = fs.SetMetadata(id2, "parent", []byte(id1))
assert.Check(t, err) assert.NilError(t, err)
mlgrMap := make(map[string]LayerGetReleaser) mlgrMap := make(map[string]LayerGetReleaser)
mlgrMap[runtime.GOOS] = &mockLayerGetReleaser{} mlgrMap[runtime.GOOS] = &mockLayerGetReleaser{}
is, err := NewImageStore(fs, mlgrMap) is, err := NewImageStore(fs, mlgrMap)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Len(is.Map(), 2)) assert.Check(t, cmp.Len(is.Map(), 2))
img1, err := is.Get(ID(id1)) img1, err := is.Get(ID(id1))
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(ID(id1), img1.computedID)) assert.Check(t, cmp.Equal(ID(id1), img1.computedID))
assert.Check(t, is.Equal(string(id1), img1.computedID.String())) assert.Check(t, cmp.Equal(string(id1), img1.computedID.String()))
img2, err := is.Get(ID(id2)) img2, err := is.Get(ID(id2))
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal("abc", img1.Comment)) assert.Check(t, cmp.Equal("abc", img1.Comment))
assert.Check(t, is.Equal("def", img2.Comment)) assert.Check(t, cmp.Equal("def", img2.Comment))
_, err = is.GetParent(ID(id1)) _, err = is.GetParent(ID(id1))
testutil.ErrorContains(t, err, "failed to read metadata") assert.ErrorContains(t, err, "failed to read metadata")
p, err := is.GetParent(ID(id2)) p, err := is.GetParent(ID(id2))
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(ID(id1), p)) assert.Check(t, cmp.Equal(ID(id1), p))
children := is.Children(ID(id1)) children := is.Children(ID(id1))
assert.Check(t, is.Len(children, 1)) assert.Check(t, cmp.Len(children, 1))
assert.Check(t, is.Equal(ID(id2), children[0])) assert.Check(t, cmp.Equal(ID(id2), children[0]))
assert.Check(t, is.Len(is.Heads(), 1)) assert.Check(t, cmp.Len(is.Heads(), 1))
sid1, err := is.Search(string(id1)[:10]) sid1, err := is.Search(string(id1)[:10])
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(ID(id1), sid1)) assert.Check(t, cmp.Equal(ID(id1), sid1))
sid1, err = is.Search(digest.Digest(id1).Hex()[:6]) sid1, err = is.Search(digest.Digest(id1).Hex()[:6])
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(ID(id1), sid1)) assert.Check(t, cmp.Equal(ID(id1), sid1))
invalidPattern := digest.Digest(id1).Hex()[1:6] invalidPattern := digest.Digest(id1).Hex()[1:6]
_, err = is.Search(invalidPattern) _, err = is.Search(invalidPattern)
testutil.ErrorContains(t, err, "No such image") assert.ErrorContains(t, err, "No such image")
} }
func TestAddDelete(t *testing.T) { func TestAddDelete(t *testing.T) {
@ -75,34 +74,34 @@ func TestAddDelete(t *testing.T) {
defer cleanup() defer cleanup()
id1, err := is.Create([]byte(`{"comment": "abc", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`)) id1, err := is.Create([]byte(`{"comment": "abc", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`))
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(ID("sha256:8d25a9c45df515f9d0fe8e4a6b1c64dd3b965a84790ddbcc7954bb9bc89eb993"), id1)) assert.Check(t, cmp.Equal(ID("sha256:8d25a9c45df515f9d0fe8e4a6b1c64dd3b965a84790ddbcc7954bb9bc89eb993"), id1))
img, err := is.Get(id1) img, err := is.Get(id1)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal("abc", img.Comment)) assert.Check(t, cmp.Equal("abc", img.Comment))
id2, err := is.Create([]byte(`{"comment": "def", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`)) id2, err := is.Create([]byte(`{"comment": "def", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`))
assert.Check(t, err) assert.NilError(t, err)
err = is.SetParent(id2, id1) err = is.SetParent(id2, id1)
assert.Check(t, err) assert.NilError(t, err)
pid1, err := is.GetParent(id2) pid1, err := is.GetParent(id2)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(pid1, id1)) assert.Check(t, cmp.Equal(pid1, id1))
_, err = is.Delete(id1) _, err = is.Delete(id1)
assert.Check(t, err) assert.NilError(t, err)
_, err = is.Get(id1) _, err = is.Get(id1)
testutil.ErrorContains(t, err, "failed to get digest") assert.ErrorContains(t, err, "failed to get digest")
_, err = is.Get(id2) _, err = is.Get(id2)
assert.Check(t, err) assert.NilError(t, err)
_, err = is.GetParent(id2) _, err = is.GetParent(id2)
testutil.ErrorContains(t, err, "failed to read metadata") assert.ErrorContains(t, err, "failed to read metadata")
} }
func TestSearchAfterDelete(t *testing.T) { func TestSearchAfterDelete(t *testing.T) {
@ -110,17 +109,17 @@ func TestSearchAfterDelete(t *testing.T) {
defer cleanup() defer cleanup()
id, err := is.Create([]byte(`{"comment": "abc", "rootfs": {"type": "layers"}}`)) id, err := is.Create([]byte(`{"comment": "abc", "rootfs": {"type": "layers"}}`))
assert.Check(t, err) assert.NilError(t, err)
id1, err := is.Search(string(id)[:15]) id1, err := is.Search(string(id)[:15])
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(id1, id)) assert.Check(t, cmp.Equal(id1, id))
_, err = is.Delete(id) _, err = is.Delete(id)
assert.Check(t, err) assert.NilError(t, err)
_, err = is.Search(string(id)[:15]) _, err = is.Search(string(id)[:15])
testutil.ErrorContains(t, err, "No such image") assert.ErrorContains(t, err, "No such image")
} }
func TestParentReset(t *testing.T) { func TestParentReset(t *testing.T) {
@ -128,20 +127,20 @@ func TestParentReset(t *testing.T) {
defer cleanup() defer cleanup()
id, err := is.Create([]byte(`{"comment": "abc1", "rootfs": {"type": "layers"}}`)) id, err := is.Create([]byte(`{"comment": "abc1", "rootfs": {"type": "layers"}}`))
assert.Check(t, err) assert.NilError(t, err)
id2, err := is.Create([]byte(`{"comment": "abc2", "rootfs": {"type": "layers"}}`)) id2, err := is.Create([]byte(`{"comment": "abc2", "rootfs": {"type": "layers"}}`))
assert.Check(t, err) assert.NilError(t, err)
id3, err := is.Create([]byte(`{"comment": "abc3", "rootfs": {"type": "layers"}}`)) id3, err := is.Create([]byte(`{"comment": "abc3", "rootfs": {"type": "layers"}}`))
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.SetParent(id, id2)) assert.Check(t, is.SetParent(id, id2))
assert.Check(t, is.Len(is.Children(id2), 1)) assert.Check(t, cmp.Len(is.Children(id2), 1))
assert.Check(t, is.SetParent(id, id3)) assert.Check(t, is.SetParent(id, id3))
assert.Check(t, is.Len(is.Children(id2), 0)) assert.Check(t, cmp.Len(is.Children(id2), 0))
assert.Check(t, is.Len(is.Children(id3), 1)) assert.Check(t, cmp.Len(is.Children(id3), 1))
} }
func defaultImageStore(t *testing.T) (Store, func()) { func defaultImageStore(t *testing.T) (Store, func()) {
@ -150,7 +149,7 @@ func defaultImageStore(t *testing.T) (Store, func()) {
mlgrMap := make(map[string]LayerGetReleaser) mlgrMap := make(map[string]LayerGetReleaser)
mlgrMap[runtime.GOOS] = &mockLayerGetReleaser{} mlgrMap[runtime.GOOS] = &mockLayerGetReleaser{}
store, err := NewImageStore(fsBackend, mlgrMap) store, err := NewImageStore(fsBackend, mlgrMap)
assert.Check(t, err) assert.NilError(t, err)
return store, cleanup return store, cleanup
} }
@ -160,17 +159,17 @@ func TestGetAndSetLastUpdated(t *testing.T) {
defer cleanup() defer cleanup()
id, err := store.Create([]byte(`{"comment": "abc1", "rootfs": {"type": "layers"}}`)) id, err := store.Create([]byte(`{"comment": "abc1", "rootfs": {"type": "layers"}}`))
assert.Check(t, err) assert.NilError(t, err)
updated, err := store.GetLastUpdated(id) updated, err := store.GetLastUpdated(id)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(updated.IsZero(), true)) assert.Check(t, cmp.Equal(updated.IsZero(), true))
assert.Check(t, store.SetLastUpdated(id)) assert.Check(t, store.SetLastUpdated(id))
updated, err = store.GetLastUpdated(id) updated, err = store.GetLastUpdated(id)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(updated.IsZero(), false)) assert.Check(t, cmp.Equal(updated.IsZero(), false))
} }
func TestStoreLen(t *testing.T) { func TestStoreLen(t *testing.T) {

View file

@ -8,6 +8,7 @@ import (
"github.com/docker/docker/integration-cli/daemon" "github.com/docker/docker/integration-cli/daemon"
"github.com/docker/docker/integration-cli/environment" "github.com/docker/docker/integration-cli/environment"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/icmd" "github.com/gotestyourself/gotestyourself/icmd"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -24,6 +25,7 @@ func SetTestEnvironment(env *environment.Execution) {
type CmdOperator func(*icmd.Cmd) func() type CmdOperator func(*icmd.Cmd) func()
type testingT interface { type testingT interface {
assert.TestingT
Fatal(args ...interface{}) Fatal(args ...interface{})
Fatalf(string, ...interface{}) Fatalf(string, ...interface{})
} }

View file

@ -298,7 +298,7 @@ COPY bar /`
_, err = io.Copy(out, resp.Body) _, err = io.Copy(out, resp.Body)
resp.Body.Close() resp.Body.Close()
assert.NilError(t, err) assert.NilError(t, err)
require.NotContains(t, out.String(), "Using cache") assert.Assert(t, !strings.Contains(out.String(), "Using cache"))
} }
// docker/for-linux#135 // docker/for-linux#135

View file

@ -10,7 +10,6 @@ import (
"github.com/docker/docker/integration/internal/request" "github.com/docker/docker/integration/internal/request"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/poll" "github.com/gotestyourself/gotestyourself/poll"
) )
@ -39,5 +38,5 @@ func TestDiff(t *testing.T) {
items, err := client.ContainerDiff(ctx, cID) items, err := client.ContainerDiff(ctx, cID)
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, items)) assert.DeepEqual(t, expected, items)
} }

View file

@ -46,10 +46,10 @@ func TestServiceWithPredefinedNetwork(t *testing.T) {
poll.WaitOn(t, serviceRunningCount(client, serviceID, instances), pollSettings) poll.WaitOn(t, serviceRunningCount(client, serviceID, instances), pollSettings)
_, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{}) _, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{})
require.NoError(t, err) assert.NilError(t, err)
err = client.ServiceRemove(context.Background(), serviceID) err = client.ServiceRemove(context.Background(), serviceID)
require.NoError(t, err) assert.NilError(t, err)
poll.WaitOn(t, serviceIsRemoved(client, serviceID), pollSettings) poll.WaitOn(t, serviceIsRemoved(client, serviceID), pollSettings)
poll.WaitOn(t, noTasks(client), pollSettings) poll.WaitOn(t, noTasks(client), pollSettings)
@ -64,7 +64,7 @@ func TestServiceWithIngressNetwork(t *testing.T) {
defer d.Stop(t) defer d.Stop(t)
client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
require.NoError(t, err) assert.NilError(t, err)
pollSettings := func(config *poll.Settings) { pollSettings := func(config *poll.Settings) {
if runtime.GOARCH == "arm64" || runtime.GOARCH == "arm" { if runtime.GOARCH == "arm64" || runtime.GOARCH == "arm" {
@ -95,7 +95,7 @@ func TestServiceWithIngressNetwork(t *testing.T) {
serviceResp, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{ serviceResp, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{
QueryRegistry: false, QueryRegistry: false,
}) })
require.NoError(t, err) assert.NilError(t, err)
serviceID := serviceResp.ID serviceID := serviceResp.ID
poll.WaitOn(t, serviceRunningCount(client, serviceID, instances), pollSettings) poll.WaitOn(t, serviceRunningCount(client, serviceID, instances), pollSettings)
@ -115,11 +115,11 @@ func TestServiceWithIngressNetwork(t *testing.T) {
Verbose: true, Verbose: true,
Scope: "swarm", Scope: "swarm",
}) })
require.NoError(t, err, "Ingress network was removed after removing service!") assert.NilError(t, err, "Ingress network was removed after removing service!")
require.NotZero(t, len(netInfo.Containers), "No load balancing endpoints in ingress network") assert.Assert(t, len(netInfo.Containers) != 0, "No load balancing endpoints in ingress network")
require.NotZero(t, len(netInfo.Peers), "No peers (including self) in ingress network") assert.Assert(t, len(netInfo.Peers) != 0, "No peers (including self) in ingress network")
_, ok := netInfo.Containers["ingress-sbox"] _, ok := netInfo.Containers["ingress-sbox"]
require.True(t, ok, "ingress-sbox not present in ingress network") assert.Assert(t, ok, "ingress-sbox not present in ingress network")
} }
func serviceRunningCount(client client.ServiceAPIClient, serviceID string, instances uint64) func(log poll.LogT) poll.Result { func serviceRunningCount(client client.ServiceAPIClient, serviceID string, instances uint64) func(log poll.LogT) poll.Result {

View file

@ -10,6 +10,7 @@ import (
swarmtypes "github.com/docker/docker/api/types/swarm" swarmtypes "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/docker/docker/integration/internal/swarm" "github.com/docker/docker/integration/internal/swarm"
"github.com/google/go-cmp/cmp"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp" is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/poll" "github.com/gotestyourself/gotestyourself/poll"
@ -18,14 +19,14 @@ import (
) )
func TestInspect(t *testing.T) { func TestInspect(t *testing.T) {
skip.IfCondition(t, testEnv.IsRemoteDaemon()) skip.If(t, testEnv.IsRemoteDaemon())
defer setupTest(t)() defer setupTest(t)()
d := swarm.NewSwarm(t, testEnv) d := swarm.NewSwarm(t, testEnv)
defer d.Stop(t) defer d.Stop(t)
client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
assert.NilError(t, err) assert.NilError(t, err)
var before = time.Now() var now = time.Now()
var instances uint64 = 2 var instances uint64 = 2
serviceSpec := fullSwarmServiceSpec("test-service-inspect", instances) serviceSpec := fullSwarmServiceSpec("test-service-inspect", instances)
@ -40,11 +41,36 @@ func TestInspect(t *testing.T) {
service, _, err := client.ServiceInspectWithRaw(ctx, id, types.ServiceInspectOptions{}) service, _, err := client.ServiceInspectWithRaw(ctx, id, types.ServiceInspectOptions{})
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(serviceSpec, service.Spec))
assert.Check(t, is.Equal(uint64(11), service.Meta.Version.Index)) expected := swarmtypes.Service{
assert.Check(t, is.Equal(id, service.ID)) ID: id,
assert.WithinDuration(t, before, service.CreatedAt, 30*time.Second) Spec: serviceSpec,
assert.WithinDuration(t, before, service.UpdatedAt, 30*time.Second) Meta: swarmtypes.Meta{
Version: swarmtypes.Version{Index: uint64(11)},
CreatedAt: now,
UpdatedAt: now,
},
}
assert.Check(t, is.DeepEqual(service, expected, cmpServiceOpts()))
}
// TODO: use helpers from gotestyourself/assert/opt when available
func cmpServiceOpts() cmp.Option {
const threshold = 20 * time.Second
metaTimeFields := func(path cmp.Path) bool {
switch path.String() {
case "Meta.CreatedAt", "Meta.UpdatedAt":
return true
}
return false
}
withinThreshold := cmp.Comparer(func(x, y time.Time) bool {
delta := x.Sub(y)
return delta < threshold && delta > -threshold
})
return cmp.FilterPath(metaTimeFields, withinThreshold)
} }
func fullSwarmServiceSpec(name string, replicas uint64) swarmtypes.ServiceSpec { func fullSwarmServiceSpec(name string, replicas uint64) swarmtypes.ServiceSpec {

View file

@ -19,17 +19,14 @@ func TestInfoBinaryCommits(t *testing.T) {
info, err := client.Info(context.Background()) info, err := client.Info(context.Background())
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, info.ContainerdCommit != nil)
assert.Check(t, "N/A" != info.ContainerdCommit.ID) assert.Check(t, "N/A" != info.ContainerdCommit.ID)
assert.Check(t, is.Equal(testEnv.DaemonInfo.ContainerdCommit.Expected, info.ContainerdCommit.Expected)) assert.Check(t, is.Equal(testEnv.DaemonInfo.ContainerdCommit.Expected, info.ContainerdCommit.Expected))
assert.Check(t, is.Equal(info.ContainerdCommit.Expected, info.ContainerdCommit.ID)) assert.Check(t, is.Equal(info.ContainerdCommit.Expected, info.ContainerdCommit.ID))
assert.Check(t, info.InitCommit != nil)
assert.Check(t, "N/A" != info.InitCommit.ID) assert.Check(t, "N/A" != info.InitCommit.ID)
assert.Check(t, is.Equal(testEnv.DaemonInfo.InitCommit.Expected, info.InitCommit.Expected)) assert.Check(t, is.Equal(testEnv.DaemonInfo.InitCommit.Expected, info.InitCommit.Expected))
assert.Check(t, is.Equal(info.InitCommit.Expected, info.InitCommit.ID)) assert.Check(t, is.Equal(info.InitCommit.Expected, info.InitCommit.ID))
assert.Check(t, info.RuncCommit != nil)
assert.Check(t, "N/A" != info.RuncCommit.ID) assert.Check(t, "N/A" != info.RuncCommit.ID)
assert.Check(t, is.Equal(testEnv.DaemonInfo.RuncCommit.Expected, info.RuncCommit.Expected)) assert.Check(t, is.Equal(testEnv.DaemonInfo.RuncCommit.Expected, info.RuncCommit.Expected))
assert.Check(t, is.Equal(info.RuncCommit.Expected, info.RuncCommit.ID)) assert.Check(t, is.Equal(info.RuncCommit.Expected, info.RuncCommit.ID))

View file

@ -15,9 +15,9 @@ func TestVersion(t *testing.T) {
version, err := client.ServerVersion(context.Background()) version, err := client.ServerVersion(context.Background())
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, version.APIVersion != nil) assert.Check(t, version.APIVersion != "")
assert.Check(t, version.Version != nil) assert.Check(t, version.Version != "")
assert.Check(t, version.MinAPIVersion != nil) assert.Check(t, version.MinAPIVersion != "")
assert.Check(t, is.Equal(testEnv.DaemonInfo.ExperimentalBuild, version.Experimental)) assert.Check(t, is.Equal(testEnv.DaemonInfo.ExperimentalBuild, version.Experimental))
assert.Check(t, is.Equal(testEnv.OSType, version.Os)) assert.Check(t, is.Equal(testEnv.OSType, version.Os))
} }

View file

@ -4,14 +4,20 @@ import (
"io" "io"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
type helperT interface {
Helper()
}
// ErrorContains checks that the error is not nil, and contains the expected // ErrorContains checks that the error is not nil, and contains the expected
// substring. // substring.
// Deprecated: use assert.Assert(t, cmp.ErrorContains(err, expected))
func ErrorContains(t assert.TestingT, err error, expectedError string, msgAndArgs ...interface{}) { func ErrorContains(t assert.TestingT, err error, expectedError string, msgAndArgs ...interface{}) {
assert.Assert(t, is.ErrorContains(err, ""), msgAndArgs) if ht, ok := t.(helperT); ok {
assert.Check(t, is.Contains(err.Error(), expectedError), msgAndArgs) ht.Helper()
}
assert.ErrorContains(t, err, expectedError, msgAndArgs...)
} }
// DevZero acts like /dev/zero but in an OS-independent fashion. // DevZero acts like /dev/zero but in an OS-independent fashion.

View file

@ -10,6 +10,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"reflect"
"runtime" "runtime"
"strings" "strings"
"testing" "testing"
@ -1338,7 +1339,7 @@ func TestDisablePigz(t *testing.T) {
// For the context canceller // For the context canceller
contextReaderCloserWrapper := outsideReaderCloserWrapper.Reader.(*ioutils.ReadCloserWrapper) contextReaderCloserWrapper := outsideReaderCloserWrapper.Reader.(*ioutils.ReadCloserWrapper)
assert.IsType(t, &gzip.Reader{}, contextReaderCloserWrapper.Reader) assert.Equal(t, reflect.TypeOf(contextReaderCloserWrapper.Reader), reflect.TypeOf(&gzip.Reader{}))
} }
func TestPigz(t *testing.T) { func TestPigz(t *testing.T) {
@ -1351,9 +1352,9 @@ func TestPigz(t *testing.T) {
_, err := exec.LookPath("unpigz") _, err := exec.LookPath("unpigz")
if err == nil { if err == nil {
t.Log("Tested whether Pigz is used, as it installed") t.Log("Tested whether Pigz is used, as it installed")
assert.IsType(t, &io.PipeReader{}, contextReaderCloserWrapper.Reader) assert.Equal(t, reflect.TypeOf(contextReaderCloserWrapper.Reader), reflect.TypeOf(&io.PipeReader{}))
} else { } else {
t.Log("Tested whether Pigz is not used, as it not installed") t.Log("Tested whether Pigz is not used, as it not installed")
assert.IsType(t, &gzip.Reader{}, contextReaderCloserWrapper.Reader) assert.Equal(t, reflect.TypeOf(contextReaderCloserWrapper.Reader), reflect.TypeOf(&gzip.Reader{}))
} }
} }

View file

@ -15,7 +15,6 @@ import (
"github.com/docker/docker/pkg/plugins/transport" "github.com/docker/docker/pkg/plugins/transport"
"github.com/docker/go-connections/tlsconfig" "github.com/docker/go-connections/tlsconfig"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -55,7 +54,6 @@ func testActive(t *testing.T, p *Plugin) {
t.Fatalf("%s:%d: deadlock in waitActive", filepath.Base(f), l) t.Fatalf("%s:%d: deadlock in waitActive", filepath.Base(f), l)
case <-done: case <-done:
} }
} }
func TestGet(t *testing.T) { func TestGet(t *testing.T) {
@ -79,12 +77,11 @@ func TestGet(t *testing.T) {
// check negative case where plugin fruit doesn't implement banana // check negative case where plugin fruit doesn't implement banana
_, err = Get("fruit", "banana") _, err = Get("fruit", "banana")
assert.Check(t, is.DeepEqual(errors.Cause(err), ErrNotImplements)) assert.Equal(t, errors.Cause(err), ErrNotImplements)
// check negative case where plugin vegetable doesn't exist // check negative case where plugin vegetable doesn't exist
_, err = Get("vegetable", "potato") _, err = Get("vegetable", "potato")
assert.Check(t, is.DeepEqual(errors.Cause(err), ErrNotFound)) assert.Equal(t, errors.Cause(err), ErrNotFound)
} }
func TestPluginWithNoManifest(t *testing.T) { func TestPluginWithNoManifest(t *testing.T) {

View file

@ -17,7 +17,7 @@ func TestEscapeProxyRead(t *testing.T) {
nr, err := reader.Read(buf) nr, err := reader.Read(buf)
assert.NilError(t, err) assert.NilError(t, err)
assert.Equal(t, nr, len(keys), fmt.Sprintf("nr %d should be equal to the number of %d", nr, len(keys))) assert.Equal(t, nr, len(keys), fmt.Sprintf("nr %d should be equal to the number of %d", nr, len(keys)))
assert.Assert(t, is.DeepEqual(keys, buf), "keys & the read buffer should be equal") assert.DeepEqual(t, keys, buf)
keys, _ = ToBytes("") keys, _ = ToBytes("")
reader = NewEscapeProxy(bytes.NewReader(keys), escapeKeys) reader = NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
@ -35,7 +35,7 @@ func TestEscapeProxyRead(t *testing.T) {
nr, err = reader.Read(buf) nr, err = reader.Read(buf)
assert.NilError(t, err) assert.NilError(t, err)
assert.Equal(t, nr, 1, fmt.Sprintf("nr %d should be equal to the number of 1", nr)) assert.Equal(t, nr, 1, fmt.Sprintf("nr %d should be equal to the number of 1", nr))
assert.Assert(t, is.DeepEqual(keys, buf), "keys & the read buffer should be equal") assert.DeepEqual(t, keys, buf)
escapeKeys, _ = ToBytes("ctrl-c") escapeKeys, _ = ToBytes("ctrl-c")
keys, _ = ToBytes("ctrl-c") keys, _ = ToBytes("ctrl-c")
@ -44,7 +44,7 @@ func TestEscapeProxyRead(t *testing.T) {
nr, err = reader.Read(buf) nr, err = reader.Read(buf)
assert.Error(t, err, "read escape sequence") assert.Error(t, err, "read escape sequence")
assert.Equal(t, nr, 0, "nr should be equal to 0") assert.Equal(t, nr, 0, "nr should be equal to 0")
assert.Assert(t, is.DeepEqual(keys, buf), "keys & the read buffer should be equal") assert.DeepEqual(t, keys, buf)
escapeKeys, _ = ToBytes("ctrl-c,ctrl-z") escapeKeys, _ = ToBytes("ctrl-c,ctrl-z")
keys, _ = ToBytes("ctrl-c,ctrl-z") keys, _ = ToBytes("ctrl-c,ctrl-z")
@ -53,11 +53,11 @@ func TestEscapeProxyRead(t *testing.T) {
nr, err = reader.Read(buf) nr, err = reader.Read(buf)
assert.NilError(t, err) assert.NilError(t, err)
assert.Equal(t, nr, 0, "nr should be equal to 0") assert.Equal(t, nr, 0, "nr should be equal to 0")
assert.Assert(t, is.DeepEqual(keys[0:1], buf), "keys & the read buffer should be equal") assert.DeepEqual(t, keys[0:1], buf)
nr, err = reader.Read(buf) nr, err = reader.Read(buf)
assert.Error(t, err, "read escape sequence") assert.Error(t, err, "read escape sequence")
assert.Equal(t, nr, 0, "nr should be equal to 0") assert.Equal(t, nr, 0, "nr should be equal to 0")
assert.Assert(t, is.DeepEqual(keys[1:], buf), "keys & the read buffer should be equal") assert.DeepEqual(t, keys[1:], buf)
escapeKeys, _ = ToBytes("ctrl-c,ctrl-z") escapeKeys, _ = ToBytes("ctrl-c,ctrl-z")
keys, _ = ToBytes("ctrl-c,DEL,+") keys, _ = ToBytes("ctrl-c,DEL,+")
@ -66,12 +66,12 @@ func TestEscapeProxyRead(t *testing.T) {
nr, err = reader.Read(buf) nr, err = reader.Read(buf)
assert.NilError(t, err) assert.NilError(t, err)
assert.Equal(t, nr, 0, "nr should be equal to 0") assert.Equal(t, nr, 0, "nr should be equal to 0")
assert.Assert(t, is.DeepEqual(keys[0:1], buf), "keys & the read buffer should be equal") assert.DeepEqual(t, keys[0:1], buf)
buf = make([]byte, len(keys)) buf = make([]byte, len(keys))
nr, err = reader.Read(buf) nr, err = reader.Read(buf)
assert.NilError(t, err) assert.NilError(t, err)
assert.Equal(t, nr, len(keys), fmt.Sprintf("nr should be equal to %d", len(keys))) assert.Equal(t, nr, len(keys), fmt.Sprintf("nr should be equal to %d", len(keys)))
assert.Assert(t, is.DeepEqual(keys, buf), "keys & the read buffer should be equal") assert.DeepEqual(t, keys, buf)
escapeKeys, _ = ToBytes("ctrl-c,ctrl-z") escapeKeys, _ = ToBytes("ctrl-c,ctrl-z")
keys, _ = ToBytes("ctrl-c,DEL") keys, _ = ToBytes("ctrl-c,DEL")
@ -80,10 +80,10 @@ func TestEscapeProxyRead(t *testing.T) {
nr, err = reader.Read(buf) nr, err = reader.Read(buf)
assert.NilError(t, err) assert.NilError(t, err)
assert.Equal(t, nr, 0, "nr should be equal to 0") assert.Equal(t, nr, 0, "nr should be equal to 0")
assert.Assert(t, is.DeepEqual(keys[0:1], buf), "keys & the read buffer should be equal") assert.DeepEqual(t, keys[0:1], buf)
buf = make([]byte, len(keys)) buf = make([]byte, len(keys))
nr, err = reader.Read(buf) nr, err = reader.Read(buf)
assert.NilError(t, err) assert.NilError(t, err)
assert.Equal(t, nr, len(keys), fmt.Sprintf("nr should be equal to %d", len(keys))) assert.Equal(t, nr, len(keys), fmt.Sprintf("nr should be equal to %d", len(keys)))
assert.Assert(t, is.DeepEqual(keys, buf), "keys & the read buffer should be equal") assert.DeepEqual(t, keys, buf)
} }

View file

@ -7,6 +7,7 @@ import (
"os" "os"
"testing" "testing"
"github.com/google/go-cmp/cmp"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
) )
@ -35,16 +36,17 @@ func TestGetWinsize(t *testing.T) {
winSize, err := GetWinsize(tty.Fd()) winSize, err := GetWinsize(tty.Fd())
assert.NilError(t, err) assert.NilError(t, err)
assert.Assert(t, winSize != nil) assert.Assert(t, winSize != nil)
assert.Assert(t, winSize.Height != nil)
assert.Assert(t, winSize.Width != nil)
newSize := Winsize{Width: 200, Height: 200, x: winSize.x, y: winSize.y} newSize := Winsize{Width: 200, Height: 200, x: winSize.x, y: winSize.y}
err = SetWinsize(tty.Fd(), &newSize) err = SetWinsize(tty.Fd(), &newSize)
assert.NilError(t, err) assert.NilError(t, err)
winSize, err = GetWinsize(tty.Fd()) winSize, err = GetWinsize(tty.Fd())
assert.NilError(t, err) assert.NilError(t, err)
assert.DeepEqual(t, *winSize, newSize) assert.DeepEqual(t, *winSize, newSize, cmpWinsize)
} }
var cmpWinsize = cmp.AllowUnexported(Winsize{})
func TestSetWinsize(t *testing.T) { func TestSetWinsize(t *testing.T) {
tty, err := newTtyForTest(t) tty, err := newTtyForTest(t)
defer tty.Close() defer tty.Close()
@ -57,7 +59,7 @@ func TestSetWinsize(t *testing.T) {
assert.NilError(t, err) assert.NilError(t, err)
winSize, err = GetWinsize(tty.Fd()) winSize, err = GetWinsize(tty.Fd())
assert.NilError(t, err) assert.NilError(t, err)
assert.DeepEqual(t, *winSize, newSize) assert.DeepEqual(t, *winSize, newSize, cmpWinsize)
} }
func TestGetFdInfo(t *testing.T) { func TestGetFdInfo(t *testing.T) {

View file

@ -12,6 +12,7 @@ import (
"github.com/docker/docker/volume" "github.com/docker/docker/volume"
"github.com/docker/docker/volume/drivers" "github.com/docker/docker/volume/drivers"
volumetestutils "github.com/docker/docker/volume/testutils" volumetestutils "github.com/docker/docker/volume/testutils"
"github.com/google/go-cmp/cmp"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp" is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
@ -359,7 +360,7 @@ func TestGet(t *testing.T) {
v2, err := s.Get("test") v2, err := s.Get("test")
assert.NilError(t, err) assert.NilError(t, err)
assert.DeepEqual(t, v1, v2) assert.DeepEqual(t, v1, v2, cmpVolume)
dv := v2.(volume.DetailedVolume) dv := v2.(volume.DetailedVolume)
assert.Equal(t, "1", dv.Labels()["a"]) assert.Equal(t, "1", dv.Labels()["a"])
@ -383,7 +384,7 @@ func TestGetWithRef(t *testing.T) {
v2, err := s.GetWithRef("test", driverName, "test-ref") v2, err := s.GetWithRef("test", driverName, "test-ref")
assert.NilError(t, err) assert.NilError(t, err)
assert.DeepEqual(t, v1, v2) assert.DeepEqual(t, v1, v2, cmpVolume)
err = s.Remove(v2) err = s.Remove(v2)
assert.Assert(t, is.ErrorContains(err, "")) assert.Assert(t, is.ErrorContains(err, ""))
@ -394,6 +395,8 @@ func TestGetWithRef(t *testing.T) {
assert.NilError(t, err) assert.NilError(t, err)
} }
var cmpVolume = cmp.AllowUnexported(volumetestutils.FakeVolume{}, volumeWrapper{})
func setupTest(t *testing.T, name string) (*VolumeStore, func(*testing.T)) { func setupTest(t *testing.T, name string) (*VolumeStore, func(*testing.T)) {
t.Helper() t.Helper()
s, cleanup := newTestStore(t) s, cleanup := newTestStore(t)