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:
commit
8d7889e510
13 changed files with 121 additions and 121 deletions
|
@ -61,7 +61,7 @@ func TestTLSCloseWriter(t *testing.T) {
|
|||
break
|
||||
}
|
||||
}
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
ts.Listener = l
|
||||
defer l.Close()
|
||||
|
@ -76,13 +76,13 @@ func TestTLSCloseWriter(t *testing.T) {
|
|||
defer ts.Close()
|
||||
|
||||
serverURL, err := url.Parse(ts.URL)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
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"}})
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer resp.Close()
|
||||
|
||||
if _, ok := resp.Conn.(types.CloseWriter); !ok {
|
||||
|
@ -90,10 +90,10 @@ func TestTLSCloseWriter(t *testing.T) {
|
|||
}
|
||||
|
||||
_, err = resp.Conn.Write([]byte("hello"))
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
b, err := ioutil.ReadAll(resp.Reader)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, string(b) == "hello")
|
||||
assert.Assert(t, resp.CloseWrite())
|
||||
|
||||
|
|
|
@ -236,30 +236,30 @@ func TestRootMountCleanup(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
testRoot, err := ioutil.TempDir("", t.Name())
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer os.RemoveAll(testRoot)
|
||||
cfg := &config.Config{}
|
||||
|
||||
err = mount.MakePrivate(testRoot)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer mount.Unmount(testRoot)
|
||||
|
||||
cfg.ExecRoot = filepath.Join(testRoot, "exec")
|
||||
cfg.Root = filepath.Join(testRoot, "daemon")
|
||||
|
||||
err = os.Mkdir(cfg.ExecRoot, 0755)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
err = os.Mkdir(cfg.Root, 0755)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
d := &Daemon{configStore: cfg, root: cfg.Root}
|
||||
unmountFile := getUnmountOnShutdownPath(cfg)
|
||||
|
||||
t.Run("regular dir no mountpoint", func(t *testing.T) {
|
||||
err = setupDaemonRootPropagation(cfg)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
_, err = os.Stat(unmountFile)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
checkMounted(t, cfg.Root, true)
|
||||
|
||||
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) {
|
||||
err = mount.MakePrivate(cfg.Root)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer mount.Unmount(cfg.Root)
|
||||
|
||||
err = setupDaemonRootPropagation(cfg)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, ensureShared(cfg.Root))
|
||||
|
||||
_, err = os.Stat(unmountFile)
|
||||
|
@ -287,11 +287,11 @@ func TestRootMountCleanup(t *testing.T) {
|
|||
// mount is pre-configured with a shared mount
|
||||
t.Run("root is a shared mountpoint", func(t *testing.T) {
|
||||
err = mount.MakeShared(cfg.Root)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer mount.Unmount(cfg.Root)
|
||||
|
||||
err = setupDaemonRootPropagation(cfg)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
if _, err := os.Stat(unmountFile); err == nil {
|
||||
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
|
||||
t.Run("old mount file is cleaned up on setup if not needed", func(t *testing.T) {
|
||||
err = mount.MakeShared(testRoot)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer mount.MakePrivate(testRoot)
|
||||
err = ioutil.WriteFile(unmountFile, nil, 0644)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
err = setupDaemonRootPropagation(cfg)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, err = os.Stat(unmountFile)
|
||||
assert.Check(t, os.IsNotExist(err), err)
|
||||
|
|
|
@ -77,15 +77,15 @@ func TestEncodeDecode(t *testing.T) {
|
|||
|
||||
decode := decodeFunc(buf)
|
||||
msg, err := decode()
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, string(msg.Line) == "hello 1\n", string(msg.Line))
|
||||
|
||||
msg, err = decode()
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, string(msg.Line) == "hello 2\n")
|
||||
|
||||
msg, err = decode()
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, string(msg.Line) == "hello 3\n")
|
||||
|
||||
_, err = decode()
|
||||
|
|
|
@ -28,13 +28,13 @@ func TestWriteLog(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
dir, err := ioutil.TempDir("", t.Name())
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
logPath := filepath.Join(dir, "test.log")
|
||||
|
||||
l, err := New(logger.Info{LogPath: logPath})
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer l.Close()
|
||||
|
||||
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
|
||||
err = l.Log(copyLogMessage(&m1))
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
err = l.Log(copyLogMessage(&m2))
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
err = l.Log(copyLogMessage(&m3))
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
f, err := os.Open(logPath)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer f.Close()
|
||||
dec := protoio.NewUint32DelimitedReader(f, binary.BigEndian, 1e6)
|
||||
|
||||
|
@ -66,19 +66,19 @@ func TestWriteLog(t *testing.T) {
|
|||
}
|
||||
|
||||
err = dec.ReadMsg(&proto)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
messageToProto(&m1, &testProto, &partial)
|
||||
assert.Check(t, is.DeepEqual(testProto, proto), "expected:\n%+v\ngot:\n%+v", testProto, proto)
|
||||
seekMsgLen()
|
||||
|
||||
err = dec.ReadMsg(&proto)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
messageToProto(&m2, &testProto, &partial)
|
||||
assert.Check(t, is.DeepEqual(testProto, proto))
|
||||
seekMsgLen()
|
||||
|
||||
err = dec.ReadMsg(&proto)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
messageToProto(&m3, &testProto, &partial)
|
||||
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()
|
||||
|
||||
dir, err := ioutil.TempDir("", t.Name())
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
logPath := filepath.Join(dir, "test.log")
|
||||
l, err := New(logger.Info{LogPath: logPath})
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer l.Close()
|
||||
|
||||
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
|
||||
err = l.Log(copyLogMessage(&m1))
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
err = l.Log(copyLogMessage(&m2))
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
err = l.Log(copyLogMessage(&m3))
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
err = l.Log(copyLogMessage(&m4))
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
lr := l.(logger.LogReader)
|
||||
|
||||
|
@ -121,12 +121,12 @@ func TestReadLog(t *testing.T) {
|
|||
case <-ctx.Done():
|
||||
assert.Assert(t, ctx.Err())
|
||||
case err := <-lw.Err:
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
case msg, open := <-lw.Msg:
|
||||
if !open {
|
||||
select {
|
||||
case err := <-lw.Err:
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
default:
|
||||
assert.Assert(t, m == nil)
|
||||
return
|
||||
|
|
|
@ -60,7 +60,7 @@ func TestTailFiles(t *testing.T) {
|
|||
case <-time.After(60 * time.Second):
|
||||
t.Fatal("timeout waiting for tail line")
|
||||
case err := <-watcher.Err:
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
case msg := <-watcher.Msg:
|
||||
assert.Assert(t, msg != nil)
|
||||
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):
|
||||
t.Fatal("timeout waiting for tail line")
|
||||
case err := <-watcher.Err:
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
case msg := <-watcher.Msg:
|
||||
assert.Assert(t, msg != nil)
|
||||
assert.Assert(t, string(msg.Line) == "Where we're going we don't need roads.", string(msg.Line))
|
||||
|
|
|
@ -370,18 +370,18 @@ func TestAuthzPluginEnsureContainerCopyToFrom(t *testing.T) {
|
|||
d.StartWithBusybox(t, "--authorization-plugin="+testAuthZPlugin, "--authorization-plugin="+testAuthZPlugin)
|
||||
|
||||
dir, err := ioutil.TempDir("", t.Name())
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
f, err := ioutil.TempFile(dir, "send")
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer f.Close()
|
||||
|
||||
buf := make([]byte, 1024)
|
||||
fileSize := len(buf) * 1024 * 10
|
||||
for written := 0; written < fileSize; {
|
||||
n, err := f.Write(buf)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
written += n
|
||||
}
|
||||
|
||||
|
@ -392,24 +392,24 @@ func TestAuthzPluginEnsureContainerCopyToFrom(t *testing.T) {
|
|||
defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true})
|
||||
|
||||
_, err = f.Seek(0, io.SeekStart)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
srcInfo, err := archive.CopyInfoSourcePath(f.Name(), false)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
srcArchive, err := archive.TarResource(srcInfo)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer srcArchive.Close()
|
||||
|
||||
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{})
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
rdr, _, err := c.CopyFromContainer(ctx, cID, "/test")
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
_, err = io.Copy(ioutil.Discard, rdr)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
func imageSave(client client.APIClient, path, image string) error {
|
||||
|
|
|
@ -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, err := client.ContainerAttach(context.Background(), id, types.ContainerAttachOptions{Stream: true, Stdout: true})
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
chErr := make(chan error)
|
||||
go func() {
|
||||
|
@ -62,7 +62,7 @@ func TestContinueAfterPluginCrash(t *testing.T) {
|
|||
|
||||
select {
|
||||
case err := <-chErr:
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
case <-time.After(60 * time.Second):
|
||||
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.
|
||||
// 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())
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
scanner := bufio.NewScanner(log)
|
||||
for scanner.Scan() {
|
||||
assert.Assert(t, !strings.Contains(scanner.Text(), "broken pipe"))
|
||||
|
|
|
@ -28,7 +28,7 @@ func TestPluginWithDevMounts(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
testDir, err := ioutil.TempDir("", "test-dir")
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer os.RemoveAll(testDir)
|
||||
|
||||
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})
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer func() {
|
||||
err := c.PluginRemove(ctx, "test", types.PluginRemoveOptions{Force: true})
|
||||
assert.Check(t, err)
|
||||
}()
|
||||
|
||||
p, _, err := c.PluginInspectWithRaw(ctx, "test")
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, p.Enabled)
|
||||
}
|
||||
|
|
|
@ -232,11 +232,11 @@ func TestNewTailReader(t *testing.T) {
|
|||
assert.Assert(t, lines == 0)
|
||||
return
|
||||
}
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, lines == i, "%d -- %d", lines, i)
|
||||
|
||||
b, err := ioutil.ReadAll(tr)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
expectLines := test.data[len(test.data)-i:]
|
||||
assert.Check(t, len(expectLines) == i)
|
||||
|
@ -260,10 +260,10 @@ func TestNewTailReader(t *testing.T) {
|
|||
return
|
||||
}
|
||||
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, lines == len(test.data), "%d -- %d", lines, len(test.data))
|
||||
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))
|
||||
})
|
||||
})
|
||||
|
@ -273,16 +273,16 @@ func TestNewTailReader(t *testing.T) {
|
|||
t.Run("truncated last line", func(t *testing.T) {
|
||||
t.Run("more than available", func(t *testing.T) {
|
||||
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)
|
||||
|
||||
rdr := bufio.NewReader(tail)
|
||||
data, _, err := rdr.ReadLine()
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, string(data) == "a", string(data))
|
||||
|
||||
data, _, err = rdr.ReadLine()
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, string(data) == "b", string(data))
|
||||
|
||||
_, _, err = rdr.ReadLine()
|
||||
|
@ -292,16 +292,16 @@ func TestNewTailReader(t *testing.T) {
|
|||
t.Run("truncated last line", func(t *testing.T) {
|
||||
t.Run("exact", func(t *testing.T) {
|
||||
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)
|
||||
|
||||
rdr := bufio.NewReader(tail)
|
||||
data, _, err := rdr.ReadLine()
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, string(data) == "a", string(data))
|
||||
|
||||
data, _, err = rdr.ReadLine()
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, string(data) == "b", string(data))
|
||||
|
||||
_, _, err = rdr.ReadLine()
|
||||
|
@ -312,12 +312,12 @@ func TestNewTailReader(t *testing.T) {
|
|||
t.Run("truncated last line", func(t *testing.T) {
|
||||
t.Run("one line", func(t *testing.T) {
|
||||
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)
|
||||
|
||||
rdr := bufio.NewReader(tail)
|
||||
data, _, err := rdr.ReadLine()
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, string(data) == "b", string(data))
|
||||
|
||||
_, _, err = rdr.ReadLine()
|
||||
|
|
|
@ -28,7 +28,7 @@ func TestLifeCycle(t *testing.T) {
|
|||
mock.simulateStartError(false, id)
|
||||
|
||||
err = exec.Create(id, specs.Spec{}, nil, nil)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
running, _ := exec.IsRunning(id)
|
||||
assert.Assert(t, running)
|
||||
|
||||
|
@ -39,12 +39,12 @@ func TestLifeCycle(t *testing.T) {
|
|||
mock.HandleExitEvent(id) // simulate a plugin that exits
|
||||
|
||||
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()) {
|
||||
rootDir, err := ioutil.TempDir("", "test-daemon")
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, client != nil)
|
||||
assert.Assert(t, eh != nil)
|
||||
|
||||
|
|
|
@ -22,11 +22,11 @@ func TestLocalVolumeSize(t *testing.T) {
|
|||
|
||||
ds := volumedrivers.NewStore(nil)
|
||||
dir, err := ioutil.TempDir("", t.Name())
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
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(testutils.NewFakeDriver("fake"), "fake"))
|
||||
|
||||
|
@ -35,20 +35,20 @@ func TestLocalVolumeSize(t *testing.T) {
|
|||
|
||||
ctx := context.Background()
|
||||
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)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
_, err = service.Create(ctx, "test3", "fake")
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
data := make([]byte, 1024)
|
||||
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)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
ls, err := service.LocalVolumesSize(ctx)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, is.Len(ls, 2))
|
||||
|
||||
for _, v := range ls {
|
||||
|
|
|
@ -31,10 +31,10 @@ func TestServiceCreate(t *testing.T) {
|
|||
assert.Assert(t, errdefs.IsNotFound(err), err)
|
||||
|
||||
v, err := service.Create(ctx, "v1", "d1")
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
vCopy, err := service.Create(ctx, "v1", "d1")
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, is.DeepEqual(v, vCopy))
|
||||
|
||||
_, err = service.Create(ctx, "v1", "d2")
|
||||
|
@ -43,9 +43,9 @@ func TestServiceCreate(t *testing.T) {
|
|||
|
||||
assert.Assert(t, service.Remove(ctx, "v1"))
|
||||
_, err = service.Create(ctx, "v1", "d2")
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
_, 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()
|
||||
|
||||
_, err := service.Create(ctx, "v1", "d1")
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
_, err = service.Create(ctx, "v2", "d1")
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
_, 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")))
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Len(ls, 2))
|
||||
|
||||
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))
|
||||
|
||||
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))
|
||||
|
||||
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))
|
||||
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))
|
||||
|
||||
_, 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")))
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Len(ls, 2))
|
||||
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))
|
||||
|
||||
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))
|
||||
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))
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ func TestServiceRemove(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
_, 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", opts.WithPurgeOnError(true)))
|
||||
|
@ -136,15 +136,15 @@ func TestServiceGet(t *testing.T) {
|
|||
assert.Check(t, v == nil)
|
||||
|
||||
created, err := service.Create(ctx, "test", "d1")
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, created != nil)
|
||||
|
||||
v, err = service.Get(ctx, "test")
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, is.DeepEqual(created, v))
|
||||
|
||||
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)
|
||||
|
||||
v, err = service.Get(ctx, "test", opts.WithGetDriver("notarealdriver"))
|
||||
|
@ -170,16 +170,16 @@ func TestServicePrune(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
|
||||
_, err := service.Create(ctx, "test", volume.DefaultDriverName)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
_, 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")))
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, is.Len(pr.VolumesDeleted, 0))
|
||||
|
||||
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.Equal(pr.VolumesDeleted[0], "test"))
|
||||
|
||||
|
@ -187,48 +187,48 @@ func TestServicePrune(t *testing.T) {
|
|||
assert.Assert(t, IsNotExist(err), err)
|
||||
|
||||
v, err := service.Get(ctx, "test2")
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, is.Equal(v.Driver, "other"))
|
||||
|
||||
_, 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")))
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, is.Len(pr.VolumesDeleted, 1))
|
||||
assert.Assert(t, is.Equal(pr.VolumesDeleted[0], "test"))
|
||||
v, err = service.Get(ctx, "test2")
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, is.Equal(v.Driver, "other"))
|
||||
|
||||
_, 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")))
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, is.Len(pr.VolumesDeleted, 0))
|
||||
|
||||
_, 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")))
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, is.Len(pr.VolumesDeleted, 1))
|
||||
assert.Assert(t, is.Equal(pr.VolumesDeleted[0], "test"))
|
||||
|
||||
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.Equal(pr.VolumesDeleted[0], "test3"))
|
||||
|
||||
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())
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, is.Len(pr.VolumesDeleted, 0))
|
||||
assert.Assert(t, service.Release(ctx, v.Name, t.Name()))
|
||||
|
||||
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.Equal(pr.VolumesDeleted[0], "test"))
|
||||
}
|
||||
|
@ -237,10 +237,10 @@ func newTestService(t *testing.T, ds *volumedrivers.Store) (*VolumesService, fun
|
|||
t.Helper()
|
||||
|
||||
dir, err := ioutil.TempDir("", t.Name())
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
store, err := NewStore(dir, ds)
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
s := &VolumesService{vs: store, eventLogger: dummyEventLogger{}}
|
||||
return s, func() {
|
||||
assert.Check(t, s.Shutdown())
|
||||
|
|
|
@ -179,12 +179,12 @@ func TestFindByReferenced(t *testing.T) {
|
|||
}
|
||||
|
||||
dangling, _, err := s.Find(ctx, ByReferenced(false))
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, len(dangling) == 1)
|
||||
assert.Check(t, dangling[0].Name() == "fake2")
|
||||
|
||||
used, _, err := s.Find(ctx, ByReferenced(true))
|
||||
assert.Assert(t, err)
|
||||
assert.NilError(t, err)
|
||||
assert.Assert(t, len(used) == 1)
|
||||
assert.Check(t, used[0].Name() == "fake1")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue