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

Merge pull request #38605 from thaJeztah/explicit_nilerror_check

Use assert.NilError() instead of assert.Assert()
This commit is contained in:
Yong Tang 2019-01-21 12:41:53 -08:00 committed by GitHub
commit 8d7889e510
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 121 additions and 121 deletions

View file

@ -61,7 +61,7 @@ func TestTLSCloseWriter(t *testing.T) {
break break
} }
} }
assert.Assert(t, err) assert.NilError(t, err)
ts.Listener = l ts.Listener = l
defer l.Close() defer l.Close()
@ -76,13 +76,13 @@ func TestTLSCloseWriter(t *testing.T) {
defer ts.Close() defer ts.Close()
serverURL, err := url.Parse(ts.URL) serverURL, err := url.Parse(ts.URL)
assert.Assert(t, err) assert.NilError(t, err)
client, err := NewClient("tcp://"+serverURL.Host, "", ts.Client(), nil) client, err := NewClient("tcp://"+serverURL.Host, "", ts.Client(), nil)
assert.Assert(t, err) assert.NilError(t, err)
resp, err := client.postHijacked(context.Background(), "/asdf", url.Values{}, nil, map[string][]string{"Content-Type": {"text/plain"}}) resp, err := client.postHijacked(context.Background(), "/asdf", url.Values{}, nil, map[string][]string{"Content-Type": {"text/plain"}})
assert.Assert(t, err) assert.NilError(t, err)
defer resp.Close() defer resp.Close()
if _, ok := resp.Conn.(types.CloseWriter); !ok { if _, ok := resp.Conn.(types.CloseWriter); !ok {
@ -90,10 +90,10 @@ func TestTLSCloseWriter(t *testing.T) {
} }
_, err = resp.Conn.Write([]byte("hello")) _, err = resp.Conn.Write([]byte("hello"))
assert.Assert(t, err) assert.NilError(t, err)
b, err := ioutil.ReadAll(resp.Reader) b, err := ioutil.ReadAll(resp.Reader)
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, string(b) == "hello") assert.Assert(t, string(b) == "hello")
assert.Assert(t, resp.CloseWrite()) assert.Assert(t, resp.CloseWrite())

View file

@ -236,30 +236,30 @@ func TestRootMountCleanup(t *testing.T) {
t.Parallel() t.Parallel()
testRoot, err := ioutil.TempDir("", t.Name()) testRoot, err := ioutil.TempDir("", t.Name())
assert.Assert(t, err) assert.NilError(t, err)
defer os.RemoveAll(testRoot) defer os.RemoveAll(testRoot)
cfg := &config.Config{} cfg := &config.Config{}
err = mount.MakePrivate(testRoot) err = mount.MakePrivate(testRoot)
assert.Assert(t, err) assert.NilError(t, err)
defer mount.Unmount(testRoot) defer mount.Unmount(testRoot)
cfg.ExecRoot = filepath.Join(testRoot, "exec") cfg.ExecRoot = filepath.Join(testRoot, "exec")
cfg.Root = filepath.Join(testRoot, "daemon") cfg.Root = filepath.Join(testRoot, "daemon")
err = os.Mkdir(cfg.ExecRoot, 0755) err = os.Mkdir(cfg.ExecRoot, 0755)
assert.Assert(t, err) assert.NilError(t, err)
err = os.Mkdir(cfg.Root, 0755) err = os.Mkdir(cfg.Root, 0755)
assert.Assert(t, err) assert.NilError(t, err)
d := &Daemon{configStore: cfg, root: cfg.Root} d := &Daemon{configStore: cfg, root: cfg.Root}
unmountFile := getUnmountOnShutdownPath(cfg) unmountFile := getUnmountOnShutdownPath(cfg)
t.Run("regular dir no mountpoint", func(t *testing.T) { t.Run("regular dir no mountpoint", func(t *testing.T) {
err = setupDaemonRootPropagation(cfg) err = setupDaemonRootPropagation(cfg)
assert.Assert(t, err) assert.NilError(t, err)
_, err = os.Stat(unmountFile) _, err = os.Stat(unmountFile)
assert.Assert(t, err) assert.NilError(t, err)
checkMounted(t, cfg.Root, true) checkMounted(t, cfg.Root, true)
assert.Assert(t, d.cleanupMounts()) assert.Assert(t, d.cleanupMounts())
@ -271,11 +271,11 @@ func TestRootMountCleanup(t *testing.T) {
t.Run("root is a private mountpoint", func(t *testing.T) { t.Run("root is a private mountpoint", func(t *testing.T) {
err = mount.MakePrivate(cfg.Root) err = mount.MakePrivate(cfg.Root)
assert.Assert(t, err) assert.NilError(t, err)
defer mount.Unmount(cfg.Root) defer mount.Unmount(cfg.Root)
err = setupDaemonRootPropagation(cfg) err = setupDaemonRootPropagation(cfg)
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, ensureShared(cfg.Root)) assert.Check(t, ensureShared(cfg.Root))
_, err = os.Stat(unmountFile) _, err = os.Stat(unmountFile)
@ -287,11 +287,11 @@ func TestRootMountCleanup(t *testing.T) {
// mount is pre-configured with a shared mount // mount is pre-configured with a shared mount
t.Run("root is a shared mountpoint", func(t *testing.T) { t.Run("root is a shared mountpoint", func(t *testing.T) {
err = mount.MakeShared(cfg.Root) err = mount.MakeShared(cfg.Root)
assert.Assert(t, err) assert.NilError(t, err)
defer mount.Unmount(cfg.Root) defer mount.Unmount(cfg.Root)
err = setupDaemonRootPropagation(cfg) err = setupDaemonRootPropagation(cfg)
assert.Assert(t, err) assert.NilError(t, err)
if _, err := os.Stat(unmountFile); err == nil { if _, err := os.Stat(unmountFile); err == nil {
t.Fatal("unmount file should not exist") t.Fatal("unmount file should not exist")
@ -305,13 +305,13 @@ func TestRootMountCleanup(t *testing.T) {
// does not need mount but unmount file exists from previous run // does not need mount but unmount file exists from previous run
t.Run("old mount file is cleaned up on setup if not needed", func(t *testing.T) { t.Run("old mount file is cleaned up on setup if not needed", func(t *testing.T) {
err = mount.MakeShared(testRoot) err = mount.MakeShared(testRoot)
assert.Assert(t, err) assert.NilError(t, err)
defer mount.MakePrivate(testRoot) defer mount.MakePrivate(testRoot)
err = ioutil.WriteFile(unmountFile, nil, 0644) err = ioutil.WriteFile(unmountFile, nil, 0644)
assert.Assert(t, err) assert.NilError(t, err)
err = setupDaemonRootPropagation(cfg) err = setupDaemonRootPropagation(cfg)
assert.Assert(t, err) assert.NilError(t, err)
_, err = os.Stat(unmountFile) _, err = os.Stat(unmountFile)
assert.Check(t, os.IsNotExist(err), err) assert.Check(t, os.IsNotExist(err), err)

View file

@ -77,15 +77,15 @@ func TestEncodeDecode(t *testing.T) {
decode := decodeFunc(buf) decode := decodeFunc(buf)
msg, err := decode() msg, err := decode()
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, string(msg.Line) == "hello 1\n", string(msg.Line)) assert.Assert(t, string(msg.Line) == "hello 1\n", string(msg.Line))
msg, err = decode() msg, err = decode()
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, string(msg.Line) == "hello 2\n") assert.Assert(t, string(msg.Line) == "hello 2\n")
msg, err = decode() msg, err = decode()
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, string(msg.Line) == "hello 3\n") assert.Assert(t, string(msg.Line) == "hello 3\n")
_, err = decode() _, err = decode()

View file

@ -28,13 +28,13 @@ func TestWriteLog(t *testing.T) {
t.Parallel() t.Parallel()
dir, err := ioutil.TempDir("", t.Name()) dir, err := ioutil.TempDir("", t.Name())
assert.Assert(t, err) assert.NilError(t, err)
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
logPath := filepath.Join(dir, "test.log") logPath := filepath.Join(dir, "test.log")
l, err := New(logger.Info{LogPath: logPath}) l, err := New(logger.Info{LogPath: logPath})
assert.Assert(t, err) assert.NilError(t, err)
defer l.Close() defer l.Close()
m1 := logger.Message{Source: "stdout", Timestamp: time.Now().Add(-1 * 30 * time.Minute), Line: []byte("message 1")} m1 := logger.Message{Source: "stdout", Timestamp: time.Now().Add(-1 * 30 * time.Minute), Line: []byte("message 1")}
@ -43,14 +43,14 @@ func TestWriteLog(t *testing.T) {
// copy the log message because the underying log writer resets the log message and returns it to a buffer pool // copy the log message because the underying log writer resets the log message and returns it to a buffer pool
err = l.Log(copyLogMessage(&m1)) err = l.Log(copyLogMessage(&m1))
assert.Assert(t, err) assert.NilError(t, err)
err = l.Log(copyLogMessage(&m2)) err = l.Log(copyLogMessage(&m2))
assert.Assert(t, err) assert.NilError(t, err)
err = l.Log(copyLogMessage(&m3)) err = l.Log(copyLogMessage(&m3))
assert.Assert(t, err) assert.NilError(t, err)
f, err := os.Open(logPath) f, err := os.Open(logPath)
assert.Assert(t, err) assert.NilError(t, err)
defer f.Close() defer f.Close()
dec := protoio.NewUint32DelimitedReader(f, binary.BigEndian, 1e6) dec := protoio.NewUint32DelimitedReader(f, binary.BigEndian, 1e6)
@ -66,19 +66,19 @@ func TestWriteLog(t *testing.T) {
} }
err = dec.ReadMsg(&proto) err = dec.ReadMsg(&proto)
assert.Assert(t, err) assert.NilError(t, err)
messageToProto(&m1, &testProto, &partial) messageToProto(&m1, &testProto, &partial)
assert.Check(t, is.DeepEqual(testProto, proto), "expected:\n%+v\ngot:\n%+v", testProto, proto) assert.Check(t, is.DeepEqual(testProto, proto), "expected:\n%+v\ngot:\n%+v", testProto, proto)
seekMsgLen() seekMsgLen()
err = dec.ReadMsg(&proto) err = dec.ReadMsg(&proto)
assert.Assert(t, err) assert.NilError(t, err)
messageToProto(&m2, &testProto, &partial) messageToProto(&m2, &testProto, &partial)
assert.Check(t, is.DeepEqual(testProto, proto)) assert.Check(t, is.DeepEqual(testProto, proto))
seekMsgLen() seekMsgLen()
err = dec.ReadMsg(&proto) err = dec.ReadMsg(&proto)
assert.Assert(t, err) assert.NilError(t, err)
messageToProto(&m3, &testProto, &partial) messageToProto(&m3, &testProto, &partial)
assert.Check(t, is.DeepEqual(testProto, proto), "expected:\n%+v\ngot:\n%+v", testProto, proto) assert.Check(t, is.DeepEqual(testProto, proto), "expected:\n%+v\ngot:\n%+v", testProto, proto)
} }
@ -87,12 +87,12 @@ func TestReadLog(t *testing.T) {
t.Parallel() t.Parallel()
dir, err := ioutil.TempDir("", t.Name()) dir, err := ioutil.TempDir("", t.Name())
assert.Assert(t, err) assert.NilError(t, err)
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
logPath := filepath.Join(dir, "test.log") logPath := filepath.Join(dir, "test.log")
l, err := New(logger.Info{LogPath: logPath}) l, err := New(logger.Info{LogPath: logPath})
assert.Assert(t, err) assert.NilError(t, err)
defer l.Close() defer l.Close()
m1 := logger.Message{Source: "stdout", Timestamp: time.Now().Add(-1 * 30 * time.Minute), Line: []byte("a message")} m1 := logger.Message{Source: "stdout", Timestamp: time.Now().Add(-1 * 30 * time.Minute), Line: []byte("a message")}
@ -103,13 +103,13 @@ func TestReadLog(t *testing.T) {
// copy the log message because the underlying log writer resets the log message and returns it to a buffer pool // copy the log message because the underlying log writer resets the log message and returns it to a buffer pool
err = l.Log(copyLogMessage(&m1)) err = l.Log(copyLogMessage(&m1))
assert.Assert(t, err) assert.NilError(t, err)
err = l.Log(copyLogMessage(&m2)) err = l.Log(copyLogMessage(&m2))
assert.Assert(t, err) assert.NilError(t, err)
err = l.Log(copyLogMessage(&m3)) err = l.Log(copyLogMessage(&m3))
assert.Assert(t, err) assert.NilError(t, err)
err = l.Log(copyLogMessage(&m4)) err = l.Log(copyLogMessage(&m4))
assert.Assert(t, err) assert.NilError(t, err)
lr := l.(logger.LogReader) lr := l.(logger.LogReader)
@ -121,12 +121,12 @@ func TestReadLog(t *testing.T) {
case <-ctx.Done(): case <-ctx.Done():
assert.Assert(t, ctx.Err()) assert.Assert(t, ctx.Err())
case err := <-lw.Err: case err := <-lw.Err:
assert.Assert(t, err) assert.NilError(t, err)
case msg, open := <-lw.Msg: case msg, open := <-lw.Msg:
if !open { if !open {
select { select {
case err := <-lw.Err: case err := <-lw.Err:
assert.Assert(t, err) assert.NilError(t, err)
default: default:
assert.Assert(t, m == nil) assert.Assert(t, m == nil)
return return

View file

@ -60,7 +60,7 @@ func TestTailFiles(t *testing.T) {
case <-time.After(60 * time.Second): case <-time.After(60 * time.Second):
t.Fatal("timeout waiting for tail line") t.Fatal("timeout waiting for tail line")
case err := <-watcher.Err: case err := <-watcher.Err:
assert.Assert(t, err) assert.NilError(t, err)
case msg := <-watcher.Msg: case msg := <-watcher.Msg:
assert.Assert(t, msg != nil) assert.Assert(t, msg != nil)
assert.Assert(t, string(msg.Line) == "Roads?", string(msg.Line)) assert.Assert(t, string(msg.Line) == "Roads?", string(msg.Line))
@ -70,7 +70,7 @@ func TestTailFiles(t *testing.T) {
case <-time.After(60 * time.Second): case <-time.After(60 * time.Second):
t.Fatal("timeout waiting for tail line") t.Fatal("timeout waiting for tail line")
case err := <-watcher.Err: case err := <-watcher.Err:
assert.Assert(t, err) assert.NilError(t, err)
case msg := <-watcher.Msg: case msg := <-watcher.Msg:
assert.Assert(t, msg != nil) assert.Assert(t, msg != nil)
assert.Assert(t, string(msg.Line) == "Where we're going we don't need roads.", string(msg.Line)) assert.Assert(t, string(msg.Line) == "Where we're going we don't need roads.", string(msg.Line))

View file

@ -370,18 +370,18 @@ func TestAuthzPluginEnsureContainerCopyToFrom(t *testing.T) {
d.StartWithBusybox(t, "--authorization-plugin="+testAuthZPlugin, "--authorization-plugin="+testAuthZPlugin) d.StartWithBusybox(t, "--authorization-plugin="+testAuthZPlugin, "--authorization-plugin="+testAuthZPlugin)
dir, err := ioutil.TempDir("", t.Name()) dir, err := ioutil.TempDir("", t.Name())
assert.Assert(t, err) assert.NilError(t, err)
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
f, err := ioutil.TempFile(dir, "send") f, err := ioutil.TempFile(dir, "send")
assert.Assert(t, err) assert.NilError(t, err)
defer f.Close() defer f.Close()
buf := make([]byte, 1024) buf := make([]byte, 1024)
fileSize := len(buf) * 1024 * 10 fileSize := len(buf) * 1024 * 10
for written := 0; written < fileSize; { for written := 0; written < fileSize; {
n, err := f.Write(buf) n, err := f.Write(buf)
assert.Assert(t, err) assert.NilError(t, err)
written += n written += n
} }
@ -392,24 +392,24 @@ func TestAuthzPluginEnsureContainerCopyToFrom(t *testing.T) {
defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true}) defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true})
_, err = f.Seek(0, io.SeekStart) _, err = f.Seek(0, io.SeekStart)
assert.Assert(t, err) assert.NilError(t, err)
srcInfo, err := archive.CopyInfoSourcePath(f.Name(), false) srcInfo, err := archive.CopyInfoSourcePath(f.Name(), false)
assert.Assert(t, err) assert.NilError(t, err)
srcArchive, err := archive.TarResource(srcInfo) srcArchive, err := archive.TarResource(srcInfo)
assert.Assert(t, err) assert.NilError(t, err)
defer srcArchive.Close() defer srcArchive.Close()
dstDir, preparedArchive, err := archive.PrepareArchiveCopy(srcArchive, srcInfo, archive.CopyInfo{Path: "/test"}) dstDir, preparedArchive, err := archive.PrepareArchiveCopy(srcArchive, srcInfo, archive.CopyInfo{Path: "/test"})
assert.Assert(t, err) assert.NilError(t, err)
err = c.CopyToContainer(ctx, cID, dstDir, preparedArchive, types.CopyToContainerOptions{}) err = c.CopyToContainer(ctx, cID, dstDir, preparedArchive, types.CopyToContainerOptions{})
assert.Assert(t, err) assert.NilError(t, err)
rdr, _, err := c.CopyFromContainer(ctx, cID, "/test") rdr, _, err := c.CopyFromContainer(ctx, cID, "/test")
assert.Assert(t, err) assert.NilError(t, err)
_, err = io.Copy(ioutil.Discard, rdr) _, err = io.Copy(ioutil.Discard, rdr)
assert.Assert(t, err) assert.NilError(t, err)
} }
func imageSave(client client.APIClient, path, image string) error { func imageSave(client client.APIClient, path, image string) error {

View file

@ -45,7 +45,7 @@ func TestContinueAfterPluginCrash(t *testing.T) {
// Attach to the container to make sure it's written a few times to stdout // Attach to the container to make sure it's written a few times to stdout
attach, err := client.ContainerAttach(context.Background(), id, types.ContainerAttachOptions{Stream: true, Stdout: true}) attach, err := client.ContainerAttach(context.Background(), id, types.ContainerAttachOptions{Stream: true, Stdout: true})
assert.Assert(t, err) assert.NilError(t, err)
chErr := make(chan error) chErr := make(chan error)
go func() { go func() {
@ -62,7 +62,7 @@ func TestContinueAfterPluginCrash(t *testing.T) {
select { select {
case err := <-chErr: case err := <-chErr:
assert.Assert(t, err) assert.NilError(t, err)
case <-time.After(60 * time.Second): case <-time.After(60 * time.Second):
t.Fatal("timeout waiting for container i/o") t.Fatal("timeout waiting for container i/o")
} }
@ -71,7 +71,7 @@ func TestContinueAfterPluginCrash(t *testing.T) {
// TODO(@cpuguy83): This is horribly hacky but is the only way to really test this case right now. // TODO(@cpuguy83): This is horribly hacky but is the only way to really test this case right now.
// It would be nice if there was a way to know that a broken pipe has occurred without looking through the logs. // It would be nice if there was a way to know that a broken pipe has occurred without looking through the logs.
log, err := os.Open(d.LogFileName()) log, err := os.Open(d.LogFileName())
assert.Assert(t, err) assert.NilError(t, err)
scanner := bufio.NewScanner(log) scanner := bufio.NewScanner(log)
for scanner.Scan() { for scanner.Scan() {
assert.Assert(t, !strings.Contains(scanner.Text(), "broken pipe")) assert.Assert(t, !strings.Contains(scanner.Text(), "broken pipe"))

View file

@ -28,7 +28,7 @@ func TestPluginWithDevMounts(t *testing.T) {
ctx := context.Background() ctx := context.Background()
testDir, err := ioutil.TempDir("", "test-dir") testDir, err := ioutil.TempDir("", "test-dir")
assert.Assert(t, err) assert.NilError(t, err)
defer os.RemoveAll(testDir) defer os.RemoveAll(testDir)
createPlugin(t, c, "test", "dummy", asVolumeDriver, func(c *plugin.Config) { createPlugin(t, c, "test", "dummy", asVolumeDriver, func(c *plugin.Config) {
@ -46,13 +46,13 @@ func TestPluginWithDevMounts(t *testing.T) {
}) })
err = c.PluginEnable(ctx, "test", types.PluginEnableOptions{Timeout: 30}) err = c.PluginEnable(ctx, "test", types.PluginEnableOptions{Timeout: 30})
assert.Assert(t, err) assert.NilError(t, err)
defer func() { defer func() {
err := c.PluginRemove(ctx, "test", types.PluginRemoveOptions{Force: true}) err := c.PluginRemove(ctx, "test", types.PluginRemoveOptions{Force: true})
assert.Check(t, err) assert.Check(t, err)
}() }()
p, _, err := c.PluginInspectWithRaw(ctx, "test") p, _, err := c.PluginInspectWithRaw(ctx, "test")
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, p.Enabled) assert.Assert(t, p.Enabled)
} }

View file

@ -232,11 +232,11 @@ func TestNewTailReader(t *testing.T) {
assert.Assert(t, lines == 0) assert.Assert(t, lines == 0)
return return
} }
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, lines == i, "%d -- %d", lines, i) assert.Check(t, lines == i, "%d -- %d", lines, i)
b, err := ioutil.ReadAll(tr) b, err := ioutil.ReadAll(tr)
assert.Assert(t, err) assert.NilError(t, err)
expectLines := test.data[len(test.data)-i:] expectLines := test.data[len(test.data)-i:]
assert.Check(t, len(expectLines) == i) assert.Check(t, len(expectLines) == i)
@ -260,10 +260,10 @@ func TestNewTailReader(t *testing.T) {
return return
} }
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, lines == len(test.data), "%d -- %d", lines, len(test.data)) assert.Check(t, lines == len(test.data), "%d -- %d", lines, len(test.data))
b, err := ioutil.ReadAll(tr) b, err := ioutil.ReadAll(tr)
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, bytes.Equal(b, []byte(s)), "\n%v\n%v", b, []byte(s)) assert.Check(t, bytes.Equal(b, []byte(s)), "\n%v\n%v", b, []byte(s))
}) })
}) })
@ -273,16 +273,16 @@ func TestNewTailReader(t *testing.T) {
t.Run("truncated last line", func(t *testing.T) { t.Run("truncated last line", func(t *testing.T) {
t.Run("more than available", func(t *testing.T) { t.Run("more than available", func(t *testing.T) {
tail, nLines, err := NewTailReader(ctx, strings.NewReader("a\nb\nextra"), 3) tail, nLines, err := NewTailReader(ctx, strings.NewReader("a\nb\nextra"), 3)
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, nLines == 2, nLines) assert.Check(t, nLines == 2, nLines)
rdr := bufio.NewReader(tail) rdr := bufio.NewReader(tail)
data, _, err := rdr.ReadLine() data, _, err := rdr.ReadLine()
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, string(data) == "a", string(data)) assert.Check(t, string(data) == "a", string(data))
data, _, err = rdr.ReadLine() data, _, err = rdr.ReadLine()
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, string(data) == "b", string(data)) assert.Check(t, string(data) == "b", string(data))
_, _, err = rdr.ReadLine() _, _, err = rdr.ReadLine()
@ -292,16 +292,16 @@ func TestNewTailReader(t *testing.T) {
t.Run("truncated last line", func(t *testing.T) { t.Run("truncated last line", func(t *testing.T) {
t.Run("exact", func(t *testing.T) { t.Run("exact", func(t *testing.T) {
tail, nLines, err := NewTailReader(ctx, strings.NewReader("a\nb\nextra"), 2) tail, nLines, err := NewTailReader(ctx, strings.NewReader("a\nb\nextra"), 2)
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, nLines == 2, nLines) assert.Check(t, nLines == 2, nLines)
rdr := bufio.NewReader(tail) rdr := bufio.NewReader(tail)
data, _, err := rdr.ReadLine() data, _, err := rdr.ReadLine()
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, string(data) == "a", string(data)) assert.Check(t, string(data) == "a", string(data))
data, _, err = rdr.ReadLine() data, _, err = rdr.ReadLine()
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, string(data) == "b", string(data)) assert.Check(t, string(data) == "b", string(data))
_, _, err = rdr.ReadLine() _, _, err = rdr.ReadLine()
@ -312,12 +312,12 @@ func TestNewTailReader(t *testing.T) {
t.Run("truncated last line", func(t *testing.T) { t.Run("truncated last line", func(t *testing.T) {
t.Run("one line", func(t *testing.T) { t.Run("one line", func(t *testing.T) {
tail, nLines, err := NewTailReader(ctx, strings.NewReader("a\nb\nextra"), 1) tail, nLines, err := NewTailReader(ctx, strings.NewReader("a\nb\nextra"), 1)
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, nLines == 1, nLines) assert.Check(t, nLines == 1, nLines)
rdr := bufio.NewReader(tail) rdr := bufio.NewReader(tail)
data, _, err := rdr.ReadLine() data, _, err := rdr.ReadLine()
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, string(data) == "b", string(data)) assert.Check(t, string(data) == "b", string(data))
_, _, err = rdr.ReadLine() _, _, err = rdr.ReadLine()

View file

@ -28,7 +28,7 @@ func TestLifeCycle(t *testing.T) {
mock.simulateStartError(false, id) mock.simulateStartError(false, id)
err = exec.Create(id, specs.Spec{}, nil, nil) err = exec.Create(id, specs.Spec{}, nil, nil)
assert.Assert(t, err) assert.NilError(t, err)
running, _ := exec.IsRunning(id) running, _ := exec.IsRunning(id)
assert.Assert(t, running) assert.Assert(t, running)
@ -39,12 +39,12 @@ func TestLifeCycle(t *testing.T) {
mock.HandleExitEvent(id) // simulate a plugin that exits mock.HandleExitEvent(id) // simulate a plugin that exits
err = exec.Create(id, specs.Spec{}, nil, nil) err = exec.Create(id, specs.Spec{}, nil, nil)
assert.Assert(t, err) assert.NilError(t, err)
} }
func setupTest(t *testing.T, client Client, eh ExitHandler) (*Executor, func()) { func setupTest(t *testing.T, client Client, eh ExitHandler) (*Executor, func()) {
rootDir, err := ioutil.TempDir("", "test-daemon") rootDir, err := ioutil.TempDir("", "test-daemon")
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, client != nil) assert.Assert(t, client != nil)
assert.Assert(t, eh != nil) assert.Assert(t, eh != nil)

View file

@ -22,11 +22,11 @@ func TestLocalVolumeSize(t *testing.T) {
ds := volumedrivers.NewStore(nil) ds := volumedrivers.NewStore(nil)
dir, err := ioutil.TempDir("", t.Name()) dir, err := ioutil.TempDir("", t.Name())
assert.Assert(t, err) assert.NilError(t, err)
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
l, err := local.New(dir, idtools.Identity{UID: os.Getuid(), GID: os.Getegid()}) l, err := local.New(dir, idtools.Identity{UID: os.Getuid(), GID: os.Getegid()})
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, ds.Register(l, volume.DefaultDriverName)) assert.Assert(t, ds.Register(l, volume.DefaultDriverName))
assert.Assert(t, ds.Register(testutils.NewFakeDriver("fake"), "fake")) assert.Assert(t, ds.Register(testutils.NewFakeDriver("fake"), "fake"))
@ -35,20 +35,20 @@ func TestLocalVolumeSize(t *testing.T) {
ctx := context.Background() ctx := context.Background()
v1, err := service.Create(ctx, "test1", volume.DefaultDriverName, opts.WithCreateReference("foo")) v1, err := service.Create(ctx, "test1", volume.DefaultDriverName, opts.WithCreateReference("foo"))
assert.Assert(t, err) assert.NilError(t, err)
v2, err := service.Create(ctx, "test2", volume.DefaultDriverName) v2, err := service.Create(ctx, "test2", volume.DefaultDriverName)
assert.Assert(t, err) assert.NilError(t, err)
_, err = service.Create(ctx, "test3", "fake") _, err = service.Create(ctx, "test3", "fake")
assert.Assert(t, err) assert.NilError(t, err)
data := make([]byte, 1024) data := make([]byte, 1024)
err = ioutil.WriteFile(filepath.Join(v1.Mountpoint, "data"), data, 0644) err = ioutil.WriteFile(filepath.Join(v1.Mountpoint, "data"), data, 0644)
assert.Assert(t, err) assert.NilError(t, err)
err = ioutil.WriteFile(filepath.Join(v2.Mountpoint, "data"), data[:1], 0644) err = ioutil.WriteFile(filepath.Join(v2.Mountpoint, "data"), data[:1], 0644)
assert.Assert(t, err) assert.NilError(t, err)
ls, err := service.LocalVolumesSize(ctx) ls, err := service.LocalVolumesSize(ctx)
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, is.Len(ls, 2)) assert.Assert(t, is.Len(ls, 2))
for _, v := range ls { for _, v := range ls {

View file

@ -31,10 +31,10 @@ func TestServiceCreate(t *testing.T) {
assert.Assert(t, errdefs.IsNotFound(err), err) assert.Assert(t, errdefs.IsNotFound(err), err)
v, err := service.Create(ctx, "v1", "d1") v, err := service.Create(ctx, "v1", "d1")
assert.Assert(t, err) assert.NilError(t, err)
vCopy, err := service.Create(ctx, "v1", "d1") vCopy, err := service.Create(ctx, "v1", "d1")
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, is.DeepEqual(v, vCopy)) assert.Assert(t, is.DeepEqual(v, vCopy))
_, err = service.Create(ctx, "v1", "d2") _, err = service.Create(ctx, "v1", "d2")
@ -43,9 +43,9 @@ func TestServiceCreate(t *testing.T) {
assert.Assert(t, service.Remove(ctx, "v1")) assert.Assert(t, service.Remove(ctx, "v1"))
_, err = service.Create(ctx, "v1", "d2") _, err = service.Create(ctx, "v1", "d2")
assert.Assert(t, err) assert.NilError(t, err)
_, err = service.Create(ctx, "v1", "d2") _, err = service.Create(ctx, "v1", "d2")
assert.Assert(t, err) assert.NilError(t, err)
} }
@ -62,45 +62,45 @@ func TestServiceList(t *testing.T) {
ctx := context.Background() ctx := context.Background()
_, err := service.Create(ctx, "v1", "d1") _, err := service.Create(ctx, "v1", "d1")
assert.Assert(t, err) assert.NilError(t, err)
_, err = service.Create(ctx, "v2", "d1") _, err = service.Create(ctx, "v2", "d1")
assert.Assert(t, err) assert.NilError(t, err)
_, err = service.Create(ctx, "v3", "d2") _, err = service.Create(ctx, "v3", "d2")
assert.Assert(t, err) assert.NilError(t, err)
ls, _, err := service.List(ctx, filters.NewArgs(filters.Arg("driver", "d1"))) ls, _, err := service.List(ctx, filters.NewArgs(filters.Arg("driver", "d1")))
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, is.Len(ls, 2)) assert.Check(t, is.Len(ls, 2))
ls, _, err = service.List(ctx, filters.NewArgs(filters.Arg("driver", "d2"))) ls, _, err = service.List(ctx, filters.NewArgs(filters.Arg("driver", "d2")))
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, is.Len(ls, 1)) assert.Check(t, is.Len(ls, 1))
ls, _, err = service.List(ctx, filters.NewArgs(filters.Arg("driver", "notexist"))) ls, _, err = service.List(ctx, filters.NewArgs(filters.Arg("driver", "notexist")))
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, is.Len(ls, 0)) assert.Check(t, is.Len(ls, 0))
ls, _, err = service.List(ctx, filters.NewArgs(filters.Arg("dangling", "true"))) ls, _, err = service.List(ctx, filters.NewArgs(filters.Arg("dangling", "true")))
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, is.Len(ls, 3)) assert.Check(t, is.Len(ls, 3))
ls, _, err = service.List(ctx, filters.NewArgs(filters.Arg("dangling", "false"))) ls, _, err = service.List(ctx, filters.NewArgs(filters.Arg("dangling", "false")))
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, is.Len(ls, 0)) assert.Check(t, is.Len(ls, 0))
_, err = service.Get(ctx, "v1", opts.WithGetReference("foo")) _, err = service.Get(ctx, "v1", opts.WithGetReference("foo"))
assert.Assert(t, err) assert.NilError(t, err)
ls, _, err = service.List(ctx, filters.NewArgs(filters.Arg("dangling", "true"))) ls, _, err = service.List(ctx, filters.NewArgs(filters.Arg("dangling", "true")))
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, is.Len(ls, 2)) assert.Check(t, is.Len(ls, 2))
ls, _, err = service.List(ctx, filters.NewArgs(filters.Arg("dangling", "false"))) ls, _, err = service.List(ctx, filters.NewArgs(filters.Arg("dangling", "false")))
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, is.Len(ls, 1)) assert.Check(t, is.Len(ls, 1))
ls, _, err = service.List(ctx, filters.NewArgs(filters.Arg("dangling", "false"), filters.Arg("driver", "d2"))) ls, _, err = service.List(ctx, filters.NewArgs(filters.Arg("dangling", "false"), filters.Arg("driver", "d2")))
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, is.Len(ls, 0)) assert.Check(t, is.Len(ls, 0))
ls, _, err = service.List(ctx, filters.NewArgs(filters.Arg("dangling", "true"), filters.Arg("driver", "d2"))) ls, _, err = service.List(ctx, filters.NewArgs(filters.Arg("dangling", "true"), filters.Arg("driver", "d2")))
assert.Assert(t, err) assert.NilError(t, err)
assert.Check(t, is.Len(ls, 1)) assert.Check(t, is.Len(ls, 1))
} }
@ -115,7 +115,7 @@ func TestServiceRemove(t *testing.T) {
ctx := context.Background() ctx := context.Background()
_, err := service.Create(ctx, "test", "d1") _, err := service.Create(ctx, "test", "d1")
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, service.Remove(ctx, "test")) assert.Assert(t, service.Remove(ctx, "test"))
assert.Assert(t, service.Remove(ctx, "test", opts.WithPurgeOnError(true))) assert.Assert(t, service.Remove(ctx, "test", opts.WithPurgeOnError(true)))
@ -136,15 +136,15 @@ func TestServiceGet(t *testing.T) {
assert.Check(t, v == nil) assert.Check(t, v == nil)
created, err := service.Create(ctx, "test", "d1") created, err := service.Create(ctx, "test", "d1")
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, created != nil) assert.Assert(t, created != nil)
v, err = service.Get(ctx, "test") v, err = service.Get(ctx, "test")
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, is.DeepEqual(created, v)) assert.Assert(t, is.DeepEqual(created, v))
v, err = service.Get(ctx, "test", opts.WithGetResolveStatus) v, err = service.Get(ctx, "test", opts.WithGetResolveStatus)
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, is.Len(v.Status, 1), v.Status) assert.Assert(t, is.Len(v.Status, 1), v.Status)
v, err = service.Get(ctx, "test", opts.WithGetDriver("notarealdriver")) v, err = service.Get(ctx, "test", opts.WithGetDriver("notarealdriver"))
@ -170,16 +170,16 @@ func TestServicePrune(t *testing.T) {
ctx := context.Background() ctx := context.Background()
_, err := service.Create(ctx, "test", volume.DefaultDriverName) _, err := service.Create(ctx, "test", volume.DefaultDriverName)
assert.Assert(t, err) assert.NilError(t, err)
_, err = service.Create(ctx, "test2", "other") _, err = service.Create(ctx, "test2", "other")
assert.Assert(t, err) assert.NilError(t, err)
pr, err := service.Prune(ctx, filters.NewArgs(filters.Arg("label", "banana"))) pr, err := service.Prune(ctx, filters.NewArgs(filters.Arg("label", "banana")))
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, is.Len(pr.VolumesDeleted, 0)) assert.Assert(t, is.Len(pr.VolumesDeleted, 0))
pr, err = service.Prune(ctx, filters.NewArgs()) pr, err = service.Prune(ctx, filters.NewArgs())
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, is.Len(pr.VolumesDeleted, 1)) assert.Assert(t, is.Len(pr.VolumesDeleted, 1))
assert.Assert(t, is.Equal(pr.VolumesDeleted[0], "test")) assert.Assert(t, is.Equal(pr.VolumesDeleted[0], "test"))
@ -187,48 +187,48 @@ func TestServicePrune(t *testing.T) {
assert.Assert(t, IsNotExist(err), err) assert.Assert(t, IsNotExist(err), err)
v, err := service.Get(ctx, "test2") v, err := service.Get(ctx, "test2")
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, is.Equal(v.Driver, "other")) assert.Assert(t, is.Equal(v.Driver, "other"))
_, err = service.Create(ctx, "test", volume.DefaultDriverName) _, err = service.Create(ctx, "test", volume.DefaultDriverName)
assert.Assert(t, err) assert.NilError(t, err)
pr, err = service.Prune(ctx, filters.NewArgs(filters.Arg("label!", "banana"))) pr, err = service.Prune(ctx, filters.NewArgs(filters.Arg("label!", "banana")))
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, is.Len(pr.VolumesDeleted, 1)) assert.Assert(t, is.Len(pr.VolumesDeleted, 1))
assert.Assert(t, is.Equal(pr.VolumesDeleted[0], "test")) assert.Assert(t, is.Equal(pr.VolumesDeleted[0], "test"))
v, err = service.Get(ctx, "test2") v, err = service.Get(ctx, "test2")
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, is.Equal(v.Driver, "other")) assert.Assert(t, is.Equal(v.Driver, "other"))
_, err = service.Create(ctx, "test", volume.DefaultDriverName, opts.WithCreateLabels(map[string]string{"banana": ""})) _, err = service.Create(ctx, "test", volume.DefaultDriverName, opts.WithCreateLabels(map[string]string{"banana": ""}))
assert.Assert(t, err) assert.NilError(t, err)
pr, err = service.Prune(ctx, filters.NewArgs(filters.Arg("label!", "banana"))) pr, err = service.Prune(ctx, filters.NewArgs(filters.Arg("label!", "banana")))
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, is.Len(pr.VolumesDeleted, 0)) assert.Assert(t, is.Len(pr.VolumesDeleted, 0))
_, err = service.Create(ctx, "test3", volume.DefaultDriverName, opts.WithCreateLabels(map[string]string{"banana": "split"})) _, err = service.Create(ctx, "test3", volume.DefaultDriverName, opts.WithCreateLabels(map[string]string{"banana": "split"}))
assert.Assert(t, err) assert.NilError(t, err)
pr, err = service.Prune(ctx, filters.NewArgs(filters.Arg("label!", "banana=split"))) pr, err = service.Prune(ctx, filters.NewArgs(filters.Arg("label!", "banana=split")))
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, is.Len(pr.VolumesDeleted, 1)) assert.Assert(t, is.Len(pr.VolumesDeleted, 1))
assert.Assert(t, is.Equal(pr.VolumesDeleted[0], "test")) assert.Assert(t, is.Equal(pr.VolumesDeleted[0], "test"))
pr, err = service.Prune(ctx, filters.NewArgs(filters.Arg("label", "banana=split"))) pr, err = service.Prune(ctx, filters.NewArgs(filters.Arg("label", "banana=split")))
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, is.Len(pr.VolumesDeleted, 1)) assert.Assert(t, is.Len(pr.VolumesDeleted, 1))
assert.Assert(t, is.Equal(pr.VolumesDeleted[0], "test3")) assert.Assert(t, is.Equal(pr.VolumesDeleted[0], "test3"))
v, err = service.Create(ctx, "test", volume.DefaultDriverName, opts.WithCreateReference(t.Name())) v, err = service.Create(ctx, "test", volume.DefaultDriverName, opts.WithCreateReference(t.Name()))
assert.Assert(t, err) assert.NilError(t, err)
pr, err = service.Prune(ctx, filters.NewArgs()) pr, err = service.Prune(ctx, filters.NewArgs())
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, is.Len(pr.VolumesDeleted, 0)) assert.Assert(t, is.Len(pr.VolumesDeleted, 0))
assert.Assert(t, service.Release(ctx, v.Name, t.Name())) assert.Assert(t, service.Release(ctx, v.Name, t.Name()))
pr, err = service.Prune(ctx, filters.NewArgs()) pr, err = service.Prune(ctx, filters.NewArgs())
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, is.Len(pr.VolumesDeleted, 1)) assert.Assert(t, is.Len(pr.VolumesDeleted, 1))
assert.Assert(t, is.Equal(pr.VolumesDeleted[0], "test")) assert.Assert(t, is.Equal(pr.VolumesDeleted[0], "test"))
} }
@ -237,10 +237,10 @@ func newTestService(t *testing.T, ds *volumedrivers.Store) (*VolumesService, fun
t.Helper() t.Helper()
dir, err := ioutil.TempDir("", t.Name()) dir, err := ioutil.TempDir("", t.Name())
assert.Assert(t, err) assert.NilError(t, err)
store, err := NewStore(dir, ds) store, err := NewStore(dir, ds)
assert.Assert(t, err) assert.NilError(t, err)
s := &VolumesService{vs: store, eventLogger: dummyEventLogger{}} s := &VolumesService{vs: store, eventLogger: dummyEventLogger{}}
return s, func() { return s, func() {
assert.Check(t, s.Shutdown()) assert.Check(t, s.Shutdown())

View file

@ -179,12 +179,12 @@ func TestFindByReferenced(t *testing.T) {
} }
dangling, _, err := s.Find(ctx, ByReferenced(false)) dangling, _, err := s.Find(ctx, ByReferenced(false))
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, len(dangling) == 1) assert.Assert(t, len(dangling) == 1)
assert.Check(t, dangling[0].Name() == "fake2") assert.Check(t, dangling[0].Name() == "fake2")
used, _, err := s.Find(ctx, ByReferenced(true)) used, _, err := s.Find(ctx, ByReferenced(true))
assert.Assert(t, err) assert.NilError(t, err)
assert.Assert(t, len(used) == 1) assert.Assert(t, len(used) == 1)
assert.Check(t, used[0].Name() == "fake1") assert.Check(t, used[0].Name() == "fake1")
} }