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 (
"bytes"
"strings"
"testing"
"github.com/gotestyourself/gotestyourself/assert"
@ -78,9 +79,9 @@ func TestWarnOnUnusedBuildArgs(t *testing.T) {
buffer := new(bytes.Buffer)
buildArgs.WarnOnUnusedBuildArgs(buffer)
out := buffer.String()
assert.NotContains(t, out, "ThisArgIsUsed")
assert.NotContains(t, out, "HTTPS_PROXY")
assert.NotContains(t, out, "HTTP_PROXY")
assert.Assert(t, !strings.Contains(out, "ThisArgIsUsed"), out)
assert.Assert(t, !strings.Contains(out, "HTTPS_PROXY"), out)
assert.Assert(t, !strings.Contains(out, "HTTP_PROXY"), out)
assert.Check(t, is.Contains(out, "ThisArgIsNotUsed"))
}

View file

@ -3,6 +3,7 @@ package parser // import "github.com/docker/docker/builder/dockerfile/parser"
import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
)
@ -16,9 +17,11 @@ func TestParseNameValOldFormat(t *testing.T) {
Value: "foo",
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) {
directive := 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) {
@ -62,8 +65,7 @@ func TestNodeFromLabels(t *testing.T) {
}
node := NodeFromLabels(labels)
assert.Check(t, is.DeepEqual(expected, node))
assert.DeepEqual(t, expected, node, cmpNodeOpt)
}
func TestParseNameValWithoutVal(t *testing.T) {

View file

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

View file

@ -89,8 +89,7 @@ func TestNewEnvClient(t *testing.T) {
env.PatchAll(t, c.envs)
apiclient, err := NewEnvClient()
if c.expectedError != "" {
assert.Check(t, is.ErrorContains(err, ""), c.doc)
assert.Check(t, is.Equal(c.expectedError, err.Error()), c.doc)
assert.Check(t, is.Error(err, c.expectedError), c.doc)
} else {
assert.Check(t, err, c.doc)
version := apiclient.ClientVersion()
@ -100,7 +99,7 @@ func TestNewEnvClient(t *testing.T) {
if c.envs["DOCKER_TLS_VERIFY"] != "" {
// pedantic checking that this is handled correctly
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)
}
}
@ -298,7 +297,7 @@ func TestClientRedirect(t *testing.T) {
cases := []struct {
httpMethod string
expectedErr error
expectedErr *url.Error
statusCode int
}{
{http.MethodGet, nil, 301},
@ -311,7 +310,13 @@ func TestClientRedirect(t *testing.T) {
req, err := http.NewRequest(tc.httpMethod, "/redirectme", nil)
assert.Check(t, err)
resp, err := client.Do(req)
assert.Check(t, is.DeepEqual(tc.expectedErr, err))
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/quota"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/go-units"
units "github.com/docker/go-units"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/sys/unix"

View file

@ -148,5 +148,5 @@ func testRetrieveQuota(t *testing.T, ctrl *Control, homeDir, testDir, testSubDir
var q Quota
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)
assert.Check(t, ok != nil)
assert.Check(t, ok, "Logger does not implement LogReader")
lw := lr.ReadLogs(ReadConfig{})
@ -158,7 +158,7 @@ func TestAdapterReadLogs(t *testing.T) {
select {
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)
case <-time.After(10 * time.Second):
t.Fatal("timeout reading logs")

View file

@ -3,6 +3,7 @@ package jsonlog // import "github.com/docker/docker/daemon/logger/jsonfilelog/js
import (
"bytes"
"encoding/json"
"fmt"
"regexp"
"testing"
"time"
@ -35,7 +36,16 @@ func TestJSONLogsMarshalJSONBuf(t *testing.T) {
var buf bytes.Buffer
err := jsonLog.MarshalJSONBuf(&buf)
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/layer"
"github.com/google/go-cmp/cmp"
"github.com/gotestyourself/gotestyourself/assert"
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.Equal(childConfig.Comment, newImage.History[1].Comment))
// RootFS should be copied not mutated
assert.Check(t, parent.RootFS.DiffIDs != newImage.RootFS.DiffIDs)
assert.Check(t, !cmp.Equal(parent.RootFS.DiffIDs, newImage.RootFS.DiffIDs),
"RootFS should be copied not mutated")
}

View file

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

View file

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

View file

@ -10,7 +10,6 @@ import (
"github.com/docker/docker/integration/internal/request"
"github.com/docker/docker/pkg/archive"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/poll"
)
@ -39,5 +38,5 @@ func TestDiff(t *testing.T) {
items, err := client.ContainerDiff(ctx, cID)
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)
_, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{})
require.NoError(t, err)
assert.NilError(t, err)
err = client.ServiceRemove(context.Background(), serviceID)
require.NoError(t, err)
assert.NilError(t, err)
poll.WaitOn(t, serviceIsRemoved(client, serviceID), pollSettings)
poll.WaitOn(t, noTasks(client), pollSettings)
@ -64,7 +64,7 @@ func TestServiceWithIngressNetwork(t *testing.T) {
defer d.Stop(t)
client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
require.NoError(t, err)
assert.NilError(t, err)
pollSettings := func(config *poll.Settings) {
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{
QueryRegistry: false,
})
require.NoError(t, err)
assert.NilError(t, err)
serviceID := serviceResp.ID
poll.WaitOn(t, serviceRunningCount(client, serviceID, instances), pollSettings)
@ -115,11 +115,11 @@ func TestServiceWithIngressNetwork(t *testing.T) {
Verbose: true,
Scope: "swarm",
})
require.NoError(t, err, "Ingress network was removed after removing service!")
require.NotZero(t, len(netInfo.Containers), "No load balancing endpoints in ingress network")
require.NotZero(t, len(netInfo.Peers), "No peers (including self) in ingress network")
assert.NilError(t, err, "Ingress network was removed after removing service!")
assert.Assert(t, len(netInfo.Containers) != 0, "No load balancing endpoints in ingress network")
assert.Assert(t, len(netInfo.Peers) != 0, "No peers (including self) in ingress network")
_, 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 {

View file

@ -10,6 +10,7 @@ import (
swarmtypes "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/client"
"github.com/docker/docker/integration/internal/swarm"
"github.com/google/go-cmp/cmp"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/poll"
@ -18,14 +19,14 @@ import (
)
func TestInspect(t *testing.T) {
skip.IfCondition(t, testEnv.IsRemoteDaemon())
skip.If(t, testEnv.IsRemoteDaemon())
defer setupTest(t)()
d := swarm.NewSwarm(t, testEnv)
defer d.Stop(t)
client, err := client.NewClientWithOpts(client.WithHost((d.Sock())))
assert.NilError(t, err)
var before = time.Now()
var now = time.Now()
var instances uint64 = 2
serviceSpec := fullSwarmServiceSpec("test-service-inspect", instances)
@ -40,11 +41,36 @@ func TestInspect(t *testing.T) {
service, _, err := client.ServiceInspectWithRaw(ctx, id, types.ServiceInspectOptions{})
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(serviceSpec, service.Spec))
assert.Check(t, is.Equal(uint64(11), service.Meta.Version.Index))
assert.Check(t, is.Equal(id, service.ID))
assert.WithinDuration(t, before, service.CreatedAt, 30*time.Second)
assert.WithinDuration(t, before, service.UpdatedAt, 30*time.Second)
expected := swarmtypes.Service{
ID: id,
Spec: serviceSpec,
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 {

View file

@ -19,17 +19,14 @@ func TestInfoBinaryCommits(t *testing.T) {
info, err := client.Info(context.Background())
assert.NilError(t, err)
assert.Check(t, info.ContainerdCommit != nil)
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(info.ContainerdCommit.Expected, info.ContainerdCommit.ID))
assert.Check(t, info.InitCommit != nil)
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(info.InitCommit.Expected, info.InitCommit.ID))
assert.Check(t, info.RuncCommit != nil)
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(info.RuncCommit.Expected, info.RuncCommit.ID))

View file

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

View file

@ -4,14 +4,20 @@ import (
"io"
"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
// substring.
// Deprecated: use assert.Assert(t, cmp.ErrorContains(err, expected))
func ErrorContains(t assert.TestingT, err error, expectedError string, msgAndArgs ...interface{}) {
assert.Assert(t, is.ErrorContains(err, ""), msgAndArgs)
assert.Check(t, is.Contains(err.Error(), expectedError), msgAndArgs)
if ht, ok := t.(helperT); ok {
ht.Helper()
}
assert.ErrorContains(t, err, expectedError, msgAndArgs...)
}
// DevZero acts like /dev/zero but in an OS-independent fashion.

View file

@ -10,6 +10,7 @@ import (
"os"
"os/exec"
"path/filepath"
"reflect"
"runtime"
"strings"
"testing"
@ -1338,7 +1339,7 @@ func TestDisablePigz(t *testing.T) {
// For the context canceller
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) {
@ -1351,9 +1352,9 @@ func TestPigz(t *testing.T) {
_, err := exec.LookPath("unpigz")
if err == nil {
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 {
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/go-connections/tlsconfig"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"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)
case <-done:
}
}
func TestGet(t *testing.T) {
@ -79,12 +77,11 @@ func TestGet(t *testing.T) {
// check negative case where plugin fruit doesn't implement 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
_, 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) {

View file

@ -17,7 +17,7 @@ func TestEscapeProxyRead(t *testing.T) {
nr, err := reader.Read(buf)
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.Assert(t, is.DeepEqual(keys, buf), "keys & the read buffer should be equal")
assert.DeepEqual(t, keys, buf)
keys, _ = ToBytes("")
reader = NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
@ -35,7 +35,7 @@ func TestEscapeProxyRead(t *testing.T) {
nr, err = reader.Read(buf)
assert.NilError(t, err)
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")
keys, _ = ToBytes("ctrl-c")
@ -44,7 +44,7 @@ func TestEscapeProxyRead(t *testing.T) {
nr, err = reader.Read(buf)
assert.Error(t, err, "read escape sequence")
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")
keys, _ = ToBytes("ctrl-c,ctrl-z")
@ -53,11 +53,11 @@ func TestEscapeProxyRead(t *testing.T) {
nr, err = reader.Read(buf)
assert.NilError(t, err)
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)
assert.Error(t, err, "read escape sequence")
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")
keys, _ = ToBytes("ctrl-c,DEL,+")
@ -66,12 +66,12 @@ func TestEscapeProxyRead(t *testing.T) {
nr, err = reader.Read(buf)
assert.NilError(t, err)
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))
nr, err = reader.Read(buf)
assert.NilError(t, err)
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")
keys, _ = ToBytes("ctrl-c,DEL")
@ -80,10 +80,10 @@ func TestEscapeProxyRead(t *testing.T) {
nr, err = reader.Read(buf)
assert.NilError(t, err)
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))
nr, err = reader.Read(buf)
assert.NilError(t, err)
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"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/gotestyourself/gotestyourself/assert"
)
@ -35,16 +36,17 @@ func TestGetWinsize(t *testing.T) {
winSize, err := GetWinsize(tty.Fd())
assert.NilError(t, err)
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}
err = SetWinsize(tty.Fd(), &newSize)
assert.NilError(t, err)
winSize, err = GetWinsize(tty.Fd())
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) {
tty, err := newTtyForTest(t)
defer tty.Close()
@ -57,7 +59,7 @@ func TestSetWinsize(t *testing.T) {
assert.NilError(t, err)
winSize, err = GetWinsize(tty.Fd())
assert.NilError(t, err)
assert.DeepEqual(t, *winSize, newSize)
assert.DeepEqual(t, *winSize, newSize, cmpWinsize)
}
func TestGetFdInfo(t *testing.T) {

View file

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