Convert assert.Check with

git grep -l -P '^\s+assert\.Check\(t, ' | \
    xargs perl -pi -e 's/^(\s+assert)\.Check(\(t, (?!is).*(\.Execute\(|\.Set\(|\.Write\(|\.Close\(|\.Untar\(|\.WriteFile\(|Validate\().*\)$)/\1.NilError\2/'

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2018-03-06 15:13:00 -05:00
parent baf65a5502
commit 078cbc9c4b
70 changed files with 183 additions and 183 deletions

View File

@ -63,7 +63,7 @@ func TestCheckpointCreateWithOptions(t *testing.T) {
cmd.SetArgs([]string{"container-foo", checkpoint})
cmd.Flags().Set("leave-running", "true")
cmd.Flags().Set("checkpoint-dir", "/dir/foo")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("container-foo", containerID))
assert.Check(t, is.Equal(checkpoint, checkpointID))
assert.Check(t, is.Equal("/dir/foo", checkpointDir))

View File

@ -60,7 +60,7 @@ func TestCheckpointListWithOptions(t *testing.T) {
cmd := newListCommand(cli)
cmd.SetArgs([]string{"container-foo"})
cmd.Flags().Set("checkpoint-dir", "/dir/foo")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("container-foo", containerID))
assert.Check(t, is.Equal("/dir/foo", checkpointDir))
golden.Assert(t, cli.OutBuffer().String(), "checkpoint-list-with-options.golden")

View File

@ -58,7 +58,7 @@ func TestCheckpointRemoveWithOptions(t *testing.T) {
cmd := newRemoveCommand(cli)
cmd.SetArgs([]string{"container-foo", "checkpoint-bar"})
cmd.Flags().Set("checkpoint-dir", "/dir/foo")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("container-foo", containerID))
assert.Check(t, is.Equal("checkpoint-bar", checkpointID))
assert.Check(t, is.Equal("/dir/foo", checkpointDir))

View File

@ -70,7 +70,7 @@ func TestConfigCreateWithName(t *testing.T) {
cmd := newConfigCreateCommand(cli)
cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, string(actual), configDataFile)
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
}
@ -109,7 +109,7 @@ func TestConfigCreateWithLabels(t *testing.T) {
cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)})
cmd.Flags().Set("label", "lbl1=Label-foo")
cmd.Flags().Set("label", "lbl2=Label-bar")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
}
@ -138,6 +138,6 @@ func TestConfigCreateWithTemplatingDriver(t *testing.T) {
cmd := newConfigCreateCommand(cli)
cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)})
cmd.Flags().Set("template-driver", expectedDriver.Name)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
}

View File

@ -95,7 +95,7 @@ func TestConfigInspectWithoutFormat(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{configInspectFunc: tc.configInspectFunc})
cmd := newConfigInspectCommand(cli)
cmd.SetArgs(tc.args)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-without-format.%s.golden", tc.name))
}
}
@ -132,7 +132,7 @@ func TestConfigInspectWithFormat(t *testing.T) {
cmd := newConfigInspectCommand(cli)
cmd.SetArgs(tc.args)
cmd.Flags().Set("format", tc.format)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-with-format.%s.golden", tc.name))
}
}
@ -166,7 +166,7 @@ func TestConfigInspectPretty(t *testing.T) {
cmd.SetArgs([]string{"configID"})
cmd.Flags().Set("pretty", "true")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-pretty.%s.golden", tc.name))
}
}

View File

@ -72,7 +72,7 @@ func TestConfigList(t *testing.T) {
},
})
cmd := newConfigListCommand(cli)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "config-list-sort.golden")
}
@ -89,7 +89,7 @@ func TestConfigListWithQuietOption(t *testing.T) {
})
cmd := newConfigListCommand(cli)
cmd.Flags().Set("quiet", "true")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "config-list-with-quiet-option.golden")
}
@ -108,7 +108,7 @@ func TestConfigListWithConfigFormat(t *testing.T) {
ConfigFormat: "{{ .Name }} {{ .Labels }}",
})
cmd := newConfigListCommand(cli)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "config-list-with-config-format.golden")
}
@ -125,7 +125,7 @@ func TestConfigListWithFormat(t *testing.T) {
})
cmd := newConfigListCommand(cli)
cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "config-list-with-format.golden")
}
@ -153,6 +153,6 @@ func TestConfigListWithFilter(t *testing.T) {
cmd := newConfigListCommand(cli)
cmd.Flags().Set("filter", "name=foo")
cmd.Flags().Set("filter", "label=lbl1=Label-bar")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "config-list-with-filter.golden")
}

View File

@ -52,7 +52,7 @@ func TestConfigRemoveWithName(t *testing.T) {
})
cmd := newConfigRemoveCommand(cli)
cmd.SetArgs(names)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.DeepEqual(names, strings.Split(strings.TrimSpace(cli.OutBuffer().String()), "\n")))
assert.Check(t, is.DeepEqual(names, removedConfigs))
}

View File

@ -25,8 +25,8 @@ func TestCIDFileNoOPWithNoFilename(t *testing.T) {
assert.NilError(t, err)
assert.DeepEqual(t, &cidFile{}, file, cmp.AllowUnexported(cidFile{}))
assert.Check(t, file.Write("id"))
assert.Check(t, file.Close())
assert.NilError(t, file.Write("id"))
assert.NilError(t, file.Close())
}
func TestNewCIDFileWhenFileAlreadyExists(t *testing.T) {
@ -46,7 +46,7 @@ func TestCIDFileCloseWithNoWrite(t *testing.T) {
assert.NilError(t, err)
assert.Check(t, is.Equal(file.path, path))
assert.Check(t, file.Close())
assert.NilError(t, file.Close())
_, err = os.Stat(path)
assert.Check(t, os.IsNotExist(err))
}
@ -60,13 +60,13 @@ func TestCIDFileCloseWithWrite(t *testing.T) {
assert.NilError(t, err)
content := "id"
assert.Check(t, file.Write(content))
assert.NilError(t, file.Write(content))
actual, err := ioutil.ReadFile(path)
assert.NilError(t, err)
assert.Check(t, is.Equal(content, string(actual)))
assert.Check(t, file.Close())
assert.NilError(t, file.Close())
_, err = os.Stat(path)
assert.NilError(t, err)
}

View File

@ -68,7 +68,7 @@ func TestContainerListWithoutFormat(t *testing.T) {
},
})
cmd := newListCommand(cli)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-without-format.golden")
}
@ -83,7 +83,7 @@ func TestContainerListNoTrunc(t *testing.T) {
})
cmd := newListCommand(cli)
cmd.Flags().Set("no-trunc", "true")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-without-format-no-trunc.golden")
}
@ -99,7 +99,7 @@ func TestContainerListNamesMultipleTime(t *testing.T) {
})
cmd := newListCommand(cli)
cmd.Flags().Set("format", "{{.Names}} {{.Names}}")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-format-name-name.golden")
}
@ -115,7 +115,7 @@ func TestContainerListFormatTemplateWithArg(t *testing.T) {
})
cmd := newListCommand(cli)
cmd.Flags().Set("format", `{{.Names}} {{.Label "some.label"}}`)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-format-with-arg.golden")
}
@ -128,7 +128,7 @@ func TestContainerListFormatSizeSetsOption(t *testing.T) {
})
cmd := newListCommand(cli)
cmd.Flags().Set("format", `{{.Size}}`)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}
func TestContainerListWithConfigFormat(t *testing.T) {
@ -144,7 +144,7 @@ func TestContainerListWithConfigFormat(t *testing.T) {
PsFormat: "{{ .Names }} {{ .Image }} {{ .Labels }}",
})
cmd := newListCommand(cli)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-with-config-format.golden")
}
@ -159,6 +159,6 @@ func TestContainerListWithFormat(t *testing.T) {
})
cmd := newListCommand(cli)
cmd.Flags().Set("format", "{{ .Names }} {{ .Image }} {{ .Labels }}")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-with-format.golden")
}

View File

@ -10,8 +10,8 @@ import (
func TestBuildContainerListOptions(t *testing.T) {
filters := opts.NewFilterOpt()
assert.Check(t, filters.Set("foo=bar"))
assert.Check(t, filters.Set("baz=foo"))
assert.NilError(t, filters.Set("foo=bar"))
assert.NilError(t, filters.Set("baz=foo"))
contexts := []struct {
psOpts *psOptions

View File

@ -21,5 +21,5 @@ func TestRunLabel(t *testing.T) {
cmd := NewRunCommand(cli)
cmd.Flags().Set("detach", "true")
cmd.SetArgs([]string{"--label", "foo", "busybox"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}

View File

@ -28,7 +28,7 @@ func TestRunBuildResetsUidAndGidInContext(t *testing.T) {
defer dest.Remove()
fakeImageBuild := func(_ context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
assert.Check(t, archive.Untar(context, dest.Path(), nil))
assert.NilError(t, archive.Untar(context, dest.Path(), nil))
body := new(bytes.Buffer)
return types.ImageBuildResponse{Body: ioutil.NopCloser(body)}, nil
@ -67,7 +67,7 @@ func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) {
buffer := new(bytes.Buffer)
tee := io.TeeReader(context, buffer)
assert.Check(t, archive.Untar(tee, dest, nil))
assert.NilError(t, archive.Untar(tee, dest, nil))
dockerfileName = options.Dockerfile
header := buffer.Bytes()[:10]
@ -132,7 +132,7 @@ COPY data /data
buffer := new(bytes.Buffer)
tee := io.TeeReader(context, buffer)
assert.Check(t, archive.Untar(tee, dest, nil))
assert.NilError(t, archive.Untar(tee, dest, nil))
dockerfileName = options.Dockerfile
body := new(bytes.Buffer)

View File

@ -92,6 +92,6 @@ func TestNewImportCommandSuccess(t *testing.T) {
cmd := NewImportCommand(test.NewFakeCli(&fakeClient{imageImportFunc: tc.imageImportFunc}))
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}
}

View File

@ -71,6 +71,6 @@ func TestNewPushCommandSuccess(t *testing.T) {
cmd := NewPushCommand(cli)
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}
}

View File

@ -126,7 +126,7 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
cmd := NewRemoveCommand(cli)
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal(tc.expectedStderr, cli.ErrBuffer().String()))
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("remove-command-success.%s.golden", tc.name))
})

View File

@ -95,7 +95,7 @@ func TestNewSaveCommandSuccess(t *testing.T) {
}))
cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
if tc.deferredFunc != nil {
tc.deferredFunc()
}

View File

@ -35,7 +35,7 @@ func TestCliNewTagCommand(t *testing.T) {
}))
cmd.SetArgs([]string{"image1", "image2"})
cmd.SetOutput(ioutil.Discard)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
value, _ := cmd.Flags().GetBool("interspersed")
assert.Check(t, !value)
}

View File

@ -66,5 +66,5 @@ func TestNetworkConnectWithFlags(t *testing.T) {
cmd.Flags().Set("ip-range", "192.168.4.0/24")
cmd.Flags().Set("gateway", "192.168.4.1/24")
cmd.Flags().Set("subnet", "192.168.4.0/24")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}

View File

@ -169,6 +169,6 @@ func TestNetworkCreateWithFlags(t *testing.T) {
cmd.Flags().Set("ip-range", "192.168.4.0/24")
cmd.Flags().Set("gateway", "192.168.4.1/24")
cmd.Flags().Set("subnet", "192.168.4.0/24")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("banana", strings.TrimSpace(cli.OutBuffer().String())))
}

View File

@ -58,6 +58,6 @@ func TestNetworkListWithFlags(t *testing.T) {
cmd := newListCommand(cli)
cmd.Flags().Set("filter", "image.name=ubuntu")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, strings.TrimSpace(cli.OutBuffer().String()), "network-list.golden")
}

View File

@ -63,7 +63,7 @@ func TestNodeDemoteNoChange(t *testing.T) {
},
}))
cmd.SetArgs([]string{"nodeID"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}
func TestNodeDemoteMultipleNode(t *testing.T) {
@ -80,5 +80,5 @@ func TestNodeDemoteMultipleNode(t *testing.T) {
},
}))
cmd.SetArgs([]string{"nodeID1", "nodeID2"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}

View File

@ -112,7 +112,7 @@ func TestNodeInspectPretty(t *testing.T) {
cmd := newInspectCommand(cli)
cmd.SetArgs([]string{"nodeID"})
cmd.Flags().Set("pretty", "true")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("node-inspect-pretty.%s.golden", tc.name))
}
}

View File

@ -72,7 +72,7 @@ func TestNodeList(t *testing.T) {
})
cmd := newListCommand(cli)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "node-list-sort.golden")
}
@ -86,7 +86,7 @@ func TestNodeListQuietShouldOnlyPrintIDs(t *testing.T) {
})
cmd := newListCommand(cli)
cmd.Flags().Set("quiet", "true")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal(cli.OutBuffer().String(), "nodeID1\n"))
}
@ -111,7 +111,7 @@ func TestNodeListDefaultFormatFromConfig(t *testing.T) {
NodesFormat: "{{.ID}}: {{.Hostname}} {{.Status}}/{{.ManagerStatus}}",
})
cmd := newListCommand(cli)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "node-list-format-from-config.golden")
}
@ -136,6 +136,6 @@ func TestNodeListFormat(t *testing.T) {
})
cmd := newListCommand(cli)
cmd.Flags().Set("format", "{{.Hostname}}: {{.ManagerStatus}}")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "node-list-format-flag.golden")
}

View File

@ -63,7 +63,7 @@ func TestNodePromoteNoChange(t *testing.T) {
},
}))
cmd.SetArgs([]string{"nodeID"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}
func TestNodePromoteMultipleNode(t *testing.T) {
@ -80,5 +80,5 @@ func TestNodePromoteMultipleNode(t *testing.T) {
},
}))
cmd.SetArgs([]string{"nodeID1", "nodeID2"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}

View File

@ -123,7 +123,7 @@ func TestNodePs(t *testing.T) {
for key, value := range tc.flags {
cmd.Flags().Set(key, value)
}
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("node-ps.%s.golden", tc.name))
}
}

View File

@ -40,5 +40,5 @@ func TestNodeRemoveErrors(t *testing.T) {
func TestNodeRemoveMultiple(t *testing.T) {
cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}))
cmd.SetArgs([]string{"nodeID1", "nodeID2"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}

View File

@ -164,6 +164,6 @@ func TestNodeUpdate(t *testing.T) {
for key, value := range tc.flags {
cmd.Flags().Set(key, value)
}
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}
}

View File

@ -109,6 +109,6 @@ func TestCreatePlugin(t *testing.T) {
cmd := newCreateCommand(cli)
cmd.SetArgs([]string{"plugin-foo", tmpDir.Path()})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
}

View File

@ -53,6 +53,6 @@ func TestPluginDisable(t *testing.T) {
})
cmd := newDisableCommand(cli)
cmd.SetArgs([]string{"plugin-foo"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
}

View File

@ -65,6 +65,6 @@ func TestPluginEnable(t *testing.T) {
cmd := newEnableCommand(cli)
cmd.SetArgs([]string{"plugin-foo"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
}

View File

@ -50,7 +50,7 @@ func TestRemove(t *testing.T) {
})
cmd := newRemoveCommand(cli)
cmd.SetArgs([]string{"plugin-foo"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
}
@ -65,7 +65,7 @@ func TestRemoveWithForceOption(t *testing.T) {
cmd := newRemoveCommand(cli)
cmd.SetArgs([]string{"plugin-foo"})
cmd.Flags().Set("force", "true")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, force)
assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
}

View File

@ -75,7 +75,7 @@ func TestSecretCreateWithName(t *testing.T) {
cmd := newSecretCreateCommand(cli)
cmd.SetArgs([]string{name, filepath.Join("testdata", secretDataFile)})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
}
@ -104,7 +104,7 @@ func TestSecretCreateWithDriver(t *testing.T) {
cmd := newSecretCreateCommand(cli)
cmd.SetArgs([]string{name})
cmd.Flags().Set("driver", expectedDriver.Name)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
}
@ -133,7 +133,7 @@ func TestSecretCreateWithTemplatingDriver(t *testing.T) {
cmd := newSecretCreateCommand(cli)
cmd.SetArgs([]string{name})
cmd.Flags().Set("template-driver", expectedDriver.Name)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
}
@ -164,6 +164,6 @@ func TestSecretCreateWithLabels(t *testing.T) {
cmd.SetArgs([]string{name, filepath.Join("testdata", secretDataFile)})
cmd.Flags().Set("label", "lbl1=Label-foo")
cmd.Flags().Set("label", "lbl2=Label-bar")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
}

View File

@ -97,7 +97,7 @@ func TestSecretInspectWithoutFormat(t *testing.T) {
})
cmd := newSecretInspectCommand(cli)
cmd.SetArgs(tc.args)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("secret-inspect-without-format.%s.golden", tc.name))
}
}
@ -134,7 +134,7 @@ func TestSecretInspectWithFormat(t *testing.T) {
cmd := newSecretInspectCommand(cli)
cmd.SetArgs(tc.args)
cmd.Flags().Set("format", tc.format)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("secret-inspect-with-format.%s.golden", tc.name))
}
}
@ -167,7 +167,7 @@ func TestSecretInspectPretty(t *testing.T) {
cmd := newSecretInspectCommand(cli)
cmd.SetArgs([]string{"secretID"})
cmd.Flags().Set("pretty", "true")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("secret-inspect-pretty.%s.golden", tc.name))
}
}

View File

@ -74,7 +74,7 @@ func TestSecretList(t *testing.T) {
},
})
cmd := newSecretListCommand(cli)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "secret-list-sort.golden")
}
@ -91,7 +91,7 @@ func TestSecretListWithQuietOption(t *testing.T) {
})
cmd := newSecretListCommand(cli)
cmd.Flags().Set("quiet", "true")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "secret-list-with-quiet-option.golden")
}
@ -110,7 +110,7 @@ func TestSecretListWithConfigFormat(t *testing.T) {
SecretFormat: "{{ .Name }} {{ .Labels }}",
})
cmd := newSecretListCommand(cli)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "secret-list-with-config-format.golden")
}
@ -127,7 +127,7 @@ func TestSecretListWithFormat(t *testing.T) {
})
cmd := newSecretListCommand(cli)
cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "secret-list-with-format.golden")
}
@ -155,6 +155,6 @@ func TestSecretListWithFilter(t *testing.T) {
cmd := newSecretListCommand(cli)
cmd.Flags().Set("filter", "name=foo")
cmd.Flags().Set("filter", "label=lbl1=Label-bar")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "secret-list-with-filter.golden")
}

View File

@ -52,7 +52,7 @@ func TestSecretRemoveWithName(t *testing.T) {
})
cmd := newSecretRemoveCommand(cli)
cmd.SetArgs(names)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.DeepEqual(names, strings.Split(strings.TrimSpace(cli.OutBuffer().String()), "\n")))
assert.Check(t, is.DeepEqual(names, removedSecrets))
}

View File

@ -23,6 +23,6 @@ func TestServiceListOrder(t *testing.T) {
})
cmd := newListCommand(cli)
cmd.Flags().Set("format", "{{.Name}}")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "service-list-sort.golden")
}

View File

@ -21,7 +21,7 @@ func TestMemBytesString(t *testing.T) {
func TestMemBytesSetAndValue(t *testing.T) {
var mem opts.MemBytes
assert.Check(t, mem.Set("5kb"))
assert.NilError(t, mem.Set("5kb"))
assert.Check(t, is.Equal(int64(5120), mem.Value()))
}
@ -32,7 +32,7 @@ func TestNanoCPUsString(t *testing.T) {
func TestNanoCPUsSetAndValue(t *testing.T) {
var cpus opts.NanoCPUs
assert.Check(t, cpus.Set("0.35"))
assert.NilError(t, cpus.Set("0.35"))
assert.Check(t, is.Equal(int64(350000000), cpus.Value()))
}
@ -47,7 +47,7 @@ func TestUint64OptString(t *testing.T) {
func TestUint64OptSetAndValue(t *testing.T) {
var opt Uint64Opt
assert.Check(t, opt.Set("14445"))
assert.NilError(t, opt.Set("14445"))
assert.Check(t, is.Equal(uint64(14445), *opt.Value()))
}

View File

@ -50,7 +50,7 @@ func TestRollback(t *testing.T) {
cmd.SetArgs(tc.args)
cmd.Flags().Set("quiet", "true")
cmd.SetOutput(ioutil.Discard)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal(strings.TrimSpace(cli.ErrBuffer().String()), tc.expectedDockerCliErr))
}
}

View File

@ -71,7 +71,7 @@ func TestListWithFormat(t *testing.T) {
})
cmd := newListCommand(cli)
cmd.Flags().Set("format", "{{ .Name }}")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-list-with-format.golden")
}
@ -87,7 +87,7 @@ func TestListWithoutFormat(t *testing.T) {
},
})
cmd := newListCommand(cli)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-list-without-format.golden")
}
@ -140,7 +140,7 @@ func TestListOrder(t *testing.T) {
},
})
cmd := newListCommand(cli)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), uc.golden)
}
}

View File

@ -74,7 +74,7 @@ func TestStackPsWithQuietOption(t *testing.T) {
cmd := newPsCommand(cli)
cmd.SetArgs([]string{"foo"})
cmd.Flags().Set("quiet", "true")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-quiet-option.golden")
}
@ -89,7 +89,7 @@ func TestStackPsWithNoTruncOption(t *testing.T) {
cmd.SetArgs([]string{"foo"})
cmd.Flags().Set("no-trunc", "true")
cmd.Flags().Set("format", "{{ .ID }}")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-no-trunc-option.golden")
}
@ -108,7 +108,7 @@ func TestStackPsWithNoResolveOption(t *testing.T) {
cmd.SetArgs([]string{"foo"})
cmd.Flags().Set("no-resolve", "true")
cmd.Flags().Set("format", "{{ .Node }}")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-no-resolve-option.golden")
}
@ -121,7 +121,7 @@ func TestStackPsWithFormat(t *testing.T) {
cmd := newPsCommand(cli)
cmd.SetArgs([]string{"foo"})
cmd.Flags().Set("format", "{{ .Name }}")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-format.golden")
}
@ -136,7 +136,7 @@ func TestStackPsWithConfigFormat(t *testing.T) {
})
cmd := newPsCommand(cli)
cmd.SetArgs([]string{"foo"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-config-format.golden")
}
@ -158,6 +158,6 @@ func TestStackPsWithoutFormat(t *testing.T) {
})
cmd := newPsCommand(cli)
cmd.SetArgs([]string{"foo"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-ps-without-format.golden")
}

View File

@ -46,7 +46,7 @@ func TestRemoveStackVersion124DoesNotRemoveConfigsOrSecrets(t *testing.T) {
cmd := newRemoveCommand(test.NewFakeCli(client))
cmd.SetArgs([]string{"foo", "bar"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.DeepEqual(buildObjectIDs(client.services), client.removedServices))
assert.Check(t, is.DeepEqual(buildObjectIDs(client.networks), client.removedNetworks))
assert.Check(t, is.Len(client.removedSecrets, 0))
@ -58,7 +58,7 @@ func TestRemoveStackVersion125DoesNotRemoveConfigs(t *testing.T) {
cmd := newRemoveCommand(test.NewFakeCli(client))
cmd.SetArgs([]string{"foo", "bar"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.DeepEqual(buildObjectIDs(client.services), client.removedServices))
assert.Check(t, is.DeepEqual(buildObjectIDs(client.networks), client.removedNetworks))
assert.Check(t, is.DeepEqual(buildObjectIDs(client.secrets), client.removedSecrets))
@ -70,7 +70,7 @@ func TestRemoveStackVersion130RemovesEverything(t *testing.T) {
cmd := newRemoveCommand(test.NewFakeCli(client))
cmd.SetArgs([]string{"foo", "bar"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.DeepEqual(buildObjectIDs(client.services), client.removedServices))
assert.Check(t, is.DeepEqual(buildObjectIDs(client.networks), client.removedNetworks))
assert.Check(t, is.DeepEqual(buildObjectIDs(client.secrets), client.removedSecrets))
@ -101,7 +101,7 @@ func TestRemoveStackSkipEmpty(t *testing.T) {
cmd := newRemoveCommand(fakeCli)
cmd.SetArgs([]string{"foo", "bar"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
expectedList := []string{"Removing service bar_service1",
"Removing service bar_service2",
"Removing secret bar_secret1",

View File

@ -88,7 +88,7 @@ func TestStackServicesEmptyServiceList(t *testing.T) {
})
cmd := newServicesCommand(fakeCli)
cmd.SetArgs([]string{"foo"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("", fakeCli.OutBuffer().String()))
assert.Check(t, is.Equal("Nothing found in stack: foo\n", fakeCli.ErrBuffer().String()))
}
@ -102,7 +102,7 @@ func TestStackServicesWithQuietOption(t *testing.T) {
cmd := newServicesCommand(cli)
cmd.Flags().Set("quiet", "true")
cmd.SetArgs([]string{"foo"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-services-with-quiet-option.golden")
}
@ -117,7 +117,7 @@ func TestStackServicesWithFormat(t *testing.T) {
cmd := newServicesCommand(cli)
cmd.SetArgs([]string{"foo"})
cmd.Flags().Set("format", "{{ .Name }}")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-services-with-format.golden")
}
@ -134,7 +134,7 @@ func TestStackServicesWithConfigFormat(t *testing.T) {
})
cmd := newServicesCommand(cli)
cmd.SetArgs([]string{"foo"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-services-with-config-format.golden")
}
@ -157,6 +157,6 @@ func TestStackServicesWithoutFormat(t *testing.T) {
})
cmd := newServicesCommand(cli)
cmd.SetArgs([]string{"foo"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-services-without-format.golden")
}

View File

@ -120,7 +120,7 @@ func TestSwarmInit(t *testing.T) {
for key, value := range tc.flags {
cmd.Flags().Set(key, value)
}
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("init-%s.golden", tc.name))
}
}

View File

@ -94,7 +94,7 @@ func TestSwarmJoin(t *testing.T) {
})
cmd := newJoinCommand(cli)
cmd.SetArgs([]string{"remote"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal(strings.TrimSpace(cli.OutBuffer().String()), tc.expected))
}
}

View File

@ -205,7 +205,7 @@ func TestSwarmJoinToken(t *testing.T) {
for key, value := range tc.flags {
cmd.Flags().Set(key, value)
}
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("jointoken-%s.golden", tc.name))
}
}

View File

@ -45,6 +45,6 @@ func TestSwarmLeaveErrors(t *testing.T) {
func TestSwarmLeave(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{})
cmd := newLeaveCommand(cli)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal("Node left the swarm.", strings.TrimSpace(cli.OutBuffer().String())))
}

View File

@ -10,25 +10,25 @@ import (
func TestNodeAddrOptionSetHostAndPort(t *testing.T) {
opt := NewNodeAddrOption("old:123")
addr := "newhost:5555"
assert.Check(t, opt.Set(addr))
assert.NilError(t, opt.Set(addr))
assert.Check(t, is.Equal(addr, opt.Value()))
}
func TestNodeAddrOptionSetHostOnly(t *testing.T) {
opt := NewListenAddrOption()
assert.Check(t, opt.Set("newhost"))
assert.NilError(t, opt.Set("newhost"))
assert.Check(t, is.Equal("newhost:2377", opt.Value()))
}
func TestNodeAddrOptionSetHostOnlyIPv6(t *testing.T) {
opt := NewListenAddrOption()
assert.Check(t, opt.Set("::1"))
assert.NilError(t, opt.Set("::1"))
assert.Check(t, is.Equal("[::1]:2377", opt.Value()))
}
func TestNodeAddrOptionSetPortOnly(t *testing.T) {
opt := NewListenAddrOption()
assert.Check(t, opt.Set(":4545"))
assert.NilError(t, opt.Set(":4545"))
assert.Check(t, is.Equal("0.0.0.0:4545", opt.Value()))
}
@ -97,15 +97,15 @@ func TestExternalCAOption(t *testing.T) {
}
for _, tc := range testCases {
opt := &ExternalCAOption{}
assert.Check(t, opt.Set(tc.externalCA))
assert.NilError(t, opt.Set(tc.externalCA))
assert.Check(t, is.Equal(tc.expected, opt.String()))
}
}
func TestExternalCAOptionMultiple(t *testing.T) {
opt := &ExternalCAOption{}
assert.Check(t, opt.Set("protocol=cfssl,url=https://example.com"))
assert.Check(t, opt.Set("protocol=CFSSL,url=anything"))
assert.NilError(t, opt.Set("protocol=cfssl,url=https://example.com"))
assert.NilError(t, opt.Set("protocol=CFSSL,url=anything"))
assert.Check(t, is.Len(opt.Value(), 2))
assert.Check(t, is.Equal("cfssl: https://example.com, cfssl: anything", opt.String()))
}

View File

@ -165,7 +165,7 @@ func TestSwarmUnlockKey(t *testing.T) {
for key, value := range tc.flags {
cmd.Flags().Set(key, value)
}
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("unlockkeys-%s.golden", tc.name))
}
}

View File

@ -94,5 +94,5 @@ func TestSwarmUnlock(t *testing.T) {
})
dockerCli.SetIn(command.NewInStream(ioutil.NopCloser(strings.NewReader(input))))
cmd := newUnlockCommand(dockerCli)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}

View File

@ -172,7 +172,7 @@ func TestSwarmUpdate(t *testing.T) {
cmd.Flags().Set(key, value)
}
cmd.SetOutput(cli.OutBuffer())
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("update-%s.golden", tc.name))
}
}

View File

@ -11,7 +11,7 @@ import (
func TestPrunePromptPre131DoesNotIncludeBuildCache(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{version: "1.30"})
cmd := newPruneCommand(cli)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
expected := `WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container

View File

@ -84,7 +84,7 @@ func TestTrustInspectCommandEmptyNotaryRepo(t *testing.T) {
cmd := newInspectCommand(cli)
cmd.SetArgs([]string{"reg/img:unsigned-tag"})
cmd.SetOutput(ioutil.Discard)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "trust-inspect-empty-repo.golden")
}
@ -93,7 +93,7 @@ func TestTrustInspectCommandFullRepoWithoutSigners(t *testing.T) {
cli.SetNotaryClient(getLoadedWithNoSignersNotaryRepository)
cmd := newInspectCommand(cli)
cmd.SetArgs([]string{"signed-repo"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "trust-inspect-full-repo-no-signers.golden")
}
@ -102,7 +102,7 @@ func TestTrustInspectCommandOneTagWithoutSigners(t *testing.T) {
cli.SetNotaryClient(getLoadedWithNoSignersNotaryRepository)
cmd := newInspectCommand(cli)
cmd.SetArgs([]string{"signed-repo:green"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "trust-inspect-one-tag-no-signers.golden")
}
@ -111,7 +111,7 @@ func TestTrustInspectCommandFullRepoWithSigners(t *testing.T) {
cli.SetNotaryClient(getLoadedNotaryRepository)
cmd := newInspectCommand(cli)
cmd.SetArgs([]string{"signed-repo"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "trust-inspect-full-repo-with-signers.golden")
}
@ -120,7 +120,7 @@ func TestTrustInspectCommandMultipleFullReposWithSigners(t *testing.T) {
cli.SetNotaryClient(getLoadedNotaryRepository)
cmd := newInspectCommand(cli)
cmd.SetArgs([]string{"signed-repo", "signed-repo"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "trust-inspect-multiple-repos-with-signers.golden")
}
@ -129,6 +129,6 @@ func TestTrustInspectCommandUnsignedTagInSignedRepo(t *testing.T) {
cli.SetNotaryClient(getLoadedNotaryRepository)
cmd := newInspectCommand(cli)
cmd.SetArgs([]string{"signed-repo:unsigned"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "trust-inspect-unsigned-tag-with-signers.golden")
}

View File

@ -125,7 +125,7 @@ func TestValidateKeyArgs(t *testing.T) {
err = validateKeyArgs("-", pubKeyCWD)
assert.Error(t, err, "key name \"-\" must start with lowercase alphanumeric characters and can include \"-\" or \"_\" after the first character")
assert.Check(t, ioutil.WriteFile(filepath.Join(pubKeyCWD, "a.pub"), []byte("abc"), notary.PrivExecPerms))
assert.NilError(t, ioutil.WriteFile(filepath.Join(pubKeyCWD, "a.pub"), []byte("abc"), notary.PrivExecPerms))
err = validateKeyArgs("a", pubKeyCWD)
assert.Error(t, err, fmt.Sprintf("public key file already exists: \"%s/a.pub\"", pubKeyCWD))

View File

@ -121,7 +121,7 @@ func testLoadKeyFromPath(t *testing.T, privKeyID string, privKeyFixture []byte)
assert.NilError(t, err)
defer os.RemoveAll(privKeyDir)
privKeyFilepath := filepath.Join(privKeyDir, "privkey.pem")
assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, notary.PrivNoExecPerms))
assert.NilError(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, notary.PrivNoExecPerms))
keyStorageDir, err := ioutil.TempDir("", "loaded-keys-")
assert.NilError(t, err)
@ -175,7 +175,7 @@ func testLoadKeyTooPermissive(t *testing.T, privKeyFixture []byte) {
assert.NilError(t, err)
defer os.RemoveAll(privKeyDir)
privKeyFilepath := filepath.Join(privKeyDir, "privkey477.pem")
assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0477))
assert.NilError(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0477))
keyStorageDir, err := ioutil.TempDir("", "loaded-keys-")
assert.NilError(t, err)
@ -187,27 +187,27 @@ func testLoadKeyTooPermissive(t *testing.T, privKeyFixture []byte) {
assert.Error(t, err, expected)
privKeyFilepath = filepath.Join(privKeyDir, "privkey667.pem")
assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0677))
assert.NilError(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0677))
_, err = getPrivKeyBytesFromPath(privKeyFilepath)
expected = fmt.Sprintf("private key file %s must not be readable or writable by others", privKeyFilepath)
assert.Error(t, err, expected)
privKeyFilepath = filepath.Join(privKeyDir, "privkey777.pem")
assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0777))
assert.NilError(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0777))
_, err = getPrivKeyBytesFromPath(privKeyFilepath)
expected = fmt.Sprintf("private key file %s must not be readable or writable by others", privKeyFilepath)
assert.Error(t, err, expected)
privKeyFilepath = filepath.Join(privKeyDir, "privkey400.pem")
assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0400))
assert.NilError(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0400))
_, err = getPrivKeyBytesFromPath(privKeyFilepath)
assert.NilError(t, err)
privKeyFilepath = filepath.Join(privKeyDir, "privkey600.pem")
assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0600))
assert.NilError(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0600))
_, err = getPrivKeyBytesFromPath(privKeyFilepath)
assert.NilError(t, err)
@ -223,7 +223,7 @@ func TestLoadPubKeyFailure(t *testing.T) {
assert.NilError(t, err)
defer os.RemoveAll(pubKeyDir)
pubKeyFilepath := filepath.Join(pubKeyDir, "pubkey.pem")
assert.Check(t, ioutil.WriteFile(pubKeyFilepath, pubKeyFixture, notary.PrivNoExecPerms))
assert.NilError(t, ioutil.WriteFile(pubKeyFilepath, pubKeyFixture, notary.PrivNoExecPerms))
keyStorageDir, err := ioutil.TempDir("", "loaded-keys-")
assert.NilError(t, err)
defer os.RemoveAll(keyStorageDir)

View File

@ -59,7 +59,7 @@ func TestTrustRevokeCommandOfflineErrors(t *testing.T) {
cmd := newRevokeCommand(cli)
cmd.SetArgs([]string{"reg-name.io/image"})
cmd.SetOutput(ioutil.Discard)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Contains(cli.OutBuffer().String(), "Please confirm you would like to delete all signature data for reg-name.io/image? [y/N] \nAborting action."))
cli = test.NewFakeCli(&fakeClient{})
@ -82,7 +82,7 @@ func TestTrustRevokeCommandUninitializedErrors(t *testing.T) {
cmd := newRevokeCommand(cli)
cmd.SetArgs([]string{"reg-name.io/image"})
cmd.SetOutput(ioutil.Discard)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Contains(cli.OutBuffer().String(), "Please confirm you would like to delete all signature data for reg-name.io/image? [y/N] \nAborting action."))
cli = test.NewFakeCli(&fakeClient{})
@ -106,7 +106,7 @@ func TestTrustRevokeCommandEmptyNotaryRepo(t *testing.T) {
cmd := newRevokeCommand(cli)
cmd.SetArgs([]string{"reg-name.io/image"})
cmd.SetOutput(ioutil.Discard)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Contains(cli.OutBuffer().String(), "Please confirm you would like to delete all signature data for reg-name.io/image? [y/N] \nAborting action."))
cli = test.NewFakeCli(&fakeClient{})
@ -129,7 +129,7 @@ func TestNewRevokeTrustAllSigConfirmation(t *testing.T) {
cli.SetNotaryClient(getEmptyTargetsNotaryRepository)
cmd := newRevokeCommand(cli)
cmd.SetArgs([]string{"alpine"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Contains(cli.OutBuffer().String(), "Please confirm you would like to delete all signature data for alpine? [y/N] \nAborting action."))
}

View File

@ -109,7 +109,7 @@ func TestSignerAddCommandInvalidRepoName(t *testing.T) {
assert.NilError(t, err)
defer os.RemoveAll(pubKeyDir)
pubKeyFilepath := filepath.Join(pubKeyDir, "pubkey.pem")
assert.Check(t, ioutil.WriteFile(pubKeyFilepath, pubKeyFixture, notary.PrivNoExecPerms))
assert.NilError(t, ioutil.WriteFile(pubKeyFilepath, pubKeyFixture, notary.PrivNoExecPerms))
cli := test.NewFakeCli(&fakeClient{})
cli.SetNotaryClient(getUninitializedNotaryRepository)

View File

@ -93,7 +93,7 @@ func TestTrustViewCommandEmptyNotaryRepoErrors(t *testing.T) {
cmd := newViewCommand(cli)
cmd.SetArgs([]string{"reg/img:unsigned-tag"})
cmd.SetOutput(ioutil.Discard)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Contains(cli.OutBuffer().String(), "No signatures for reg/img:unsigned-tag"))
assert.Check(t, is.Contains(cli.OutBuffer().String(), "Administrative keys for reg/img:"))
@ -102,7 +102,7 @@ func TestTrustViewCommandEmptyNotaryRepoErrors(t *testing.T) {
cmd = newViewCommand(cli)
cmd.SetArgs([]string{"reg/img"})
cmd.SetOutput(ioutil.Discard)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Contains(cli.OutBuffer().String(), "No signatures for reg/img"))
assert.Check(t, is.Contains(cli.OutBuffer().String(), "Administrative keys for reg/img:"))
}
@ -112,7 +112,7 @@ func TestTrustViewCommandFullRepoWithoutSigners(t *testing.T) {
cli.SetNotaryClient(getLoadedWithNoSignersNotaryRepository)
cmd := newViewCommand(cli)
cmd.SetArgs([]string{"signed-repo"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "trust-view-full-repo-no-signers.golden")
}
@ -122,7 +122,7 @@ func TestTrustViewCommandOneTagWithoutSigners(t *testing.T) {
cli.SetNotaryClient(getLoadedWithNoSignersNotaryRepository)
cmd := newViewCommand(cli)
cmd.SetArgs([]string{"signed-repo:green"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "trust-view-one-tag-no-signers.golden")
}
@ -132,7 +132,7 @@ func TestTrustViewCommandFullRepoWithSigners(t *testing.T) {
cli.SetNotaryClient(getLoadedNotaryRepository)
cmd := newViewCommand(cli)
cmd.SetArgs([]string{"signed-repo"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "trust-view-full-repo-with-signers.golden")
}
@ -142,7 +142,7 @@ func TestTrustViewCommandUnsignedTagInSignedRepo(t *testing.T) {
cli.SetNotaryClient(getLoadedNotaryRepository)
cmd := newViewCommand(cli)
cmd.SetArgs([]string{"signed-repo:unsigned"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "trust-view-unsigned-tag-with-signers.golden")
}

View File

@ -72,14 +72,14 @@ func TestVolumeCreateWithName(t *testing.T) {
// Test by flags
cmd := newCreateCommand(cli)
cmd.Flags().Set("name", name)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal(name, strings.TrimSpace(buf.String())))
// Then by args
buf.Reset()
cmd = newCreateCommand(cli)
cmd.SetArgs([]string{name})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal(name, strings.TrimSpace(buf.String())))
}
@ -121,6 +121,6 @@ func TestVolumeCreateWithFlags(t *testing.T) {
cmd.Flags().Set("opt", "baz=baz")
cmd.Flags().Set("label", "lbl1=v1")
cmd.Flags().Set("label", "lbl2=v2")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
assert.Check(t, is.Equal(name, strings.TrimSpace(cli.OutBuffer().String())))
}

View File

@ -98,7 +98,7 @@ func TestVolumeInspectWithoutFormat(t *testing.T) {
})
cmd := newInspectCommand(cli)
cmd.SetArgs(tc.args)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("volume-inspect-without-format.%s.golden", tc.name))
}
}
@ -135,7 +135,7 @@ func TestVolumeInspectWithFormat(t *testing.T) {
cmd := newInspectCommand(cli)
cmd.SetArgs(tc.args)
cmd.Flags().Set("format", tc.format)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("volume-inspect-with-format.%s.golden", tc.name))
}
}

View File

@ -64,7 +64,7 @@ func TestVolumeListWithoutFormat(t *testing.T) {
},
})
cmd := newListCommand(cli)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "volume-list-without-format.golden")
}
@ -86,7 +86,7 @@ func TestVolumeListWithConfigFormat(t *testing.T) {
VolumesFormat: "{{ .Name }} {{ .Driver }} {{ .Labels }}",
})
cmd := newListCommand(cli)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "volume-list-with-config-format.golden")
}
@ -106,6 +106,6 @@ func TestVolumeListWithFormat(t *testing.T) {
})
cmd := newListCommand(cli)
cmd.Flags().Set("format", "{{ .Name }} {{ .Driver }} {{ .Labels }}")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "volume-list-with-format.golden")
}

View File

@ -72,7 +72,7 @@ func TestVolumePruneForce(t *testing.T) {
})
cmd := NewPruneCommand(cli)
cmd.Flags().Set("force", "true")
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("volume-prune.%s.golden", tc.name))
}
}
@ -88,7 +88,7 @@ func TestVolumePrunePromptYes(t *testing.T) {
cli.SetIn(command.NewInStream(ioutil.NopCloser(strings.NewReader(input))))
cmd := NewPruneCommand(cli)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "volume-prune-yes.golden")
}
}
@ -104,7 +104,7 @@ func TestVolumePrunePromptNo(t *testing.T) {
cli.SetIn(command.NewInStream(ioutil.NopCloser(strings.NewReader(input))))
cmd := NewPruneCommand(cli)
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "volume-prune-no.golden")
}
}

View File

@ -40,5 +40,5 @@ func TestVolumeRemoveErrors(t *testing.T) {
func TestNodeRemoveMultiple(t *testing.T) {
cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}))
cmd.SetArgs([]string{"volume1", "volume2"})
assert.Check(t, cmd.Execute())
assert.NilError(t, cmd.Execute())
}

View File

@ -18,7 +18,7 @@ func TestValidate(t *testing.T) {
},
}
assert.Check(t, Validate(config, "3.0"))
assert.NilError(t, Validate(config, "3.0"))
}
func TestValidateUndefinedTopLevelOption(t *testing.T) {
@ -99,7 +99,7 @@ func TestValidatePlacement(t *testing.T) {
},
}
assert.Check(t, Validate(config, "3.3"))
assert.NilError(t, Validate(config, "3.3"))
}
func TestValidateIsolation(t *testing.T) {
@ -112,5 +112,5 @@ func TestValidateIsolation(t *testing.T) {
},
},
}
assert.Check(t, Validate(config, "3.5"))
assert.NilError(t, Validate(config, "3.5"))
}

View File

@ -16,15 +16,15 @@ func TestDurationOptString(t *testing.T) {
func TestDurationOptSetAndValue(t *testing.T) {
var duration DurationOpt
assert.Check(t, duration.Set("300s"))
assert.NilError(t, duration.Set("300s"))
assert.Check(t, is.Equal(time.Duration(300*10e8), *duration.Value()))
assert.Check(t, duration.Set("-300s"))
assert.NilError(t, duration.Set("-300s"))
assert.Check(t, is.Equal(time.Duration(-300*10e8), *duration.Value()))
}
func TestPositiveDurationOptSetAndValue(t *testing.T) {
var duration PositiveDurationOpt
assert.Check(t, duration.Set("300s"))
assert.NilError(t, duration.Set("300s"))
assert.Check(t, is.Equal(time.Duration(300*10e8), *duration.Value()))
assert.Check(t, is.Error(duration.Set("-300s"), "duration cannot be negative"))
}

View File

@ -38,7 +38,7 @@ func TestMountOptSetBindNoErrorBind(t *testing.T) {
} {
var mount MountOpt
assert.Check(t, mount.Set(testcase))
assert.NilError(t, mount.Set(testcase))
mounts := mount.Value()
assert.Assert(t, is.Len(mounts, 1))
@ -60,7 +60,7 @@ func TestMountOptSetVolumeNoError(t *testing.T) {
} {
var mount MountOpt
assert.Check(t, mount.Set(testcase))
assert.NilError(t, mount.Set(testcase))
mounts := mount.Value()
assert.Assert(t, is.Len(mounts, 1))
@ -76,7 +76,7 @@ func TestMountOptSetVolumeNoError(t *testing.T) {
// volume mount.
func TestMountOptDefaultType(t *testing.T) {
var mount MountOpt
assert.Check(t, mount.Set("target=/target,source=/foo"))
assert.NilError(t, mount.Set("target=/target,source=/foo"))
assert.Check(t, is.Equal(mounttypes.TypeVolume, mount.values[0].Type))
}
@ -103,47 +103,47 @@ func TestMountOptSetErrorInvalidReadOnly(t *testing.T) {
func TestMountOptDefaultEnableReadOnly(t *testing.T) {
var m MountOpt
assert.Check(t, m.Set("type=bind,target=/foo,source=/foo"))
assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo"))
assert.Check(t, !m.values[0].ReadOnly)
m = MountOpt{}
assert.Check(t, m.Set("type=bind,target=/foo,source=/foo,readonly"))
assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly"))
assert.Check(t, m.values[0].ReadOnly)
m = MountOpt{}
assert.Check(t, m.Set("type=bind,target=/foo,source=/foo,readonly=1"))
assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=1"))
assert.Check(t, m.values[0].ReadOnly)
m = MountOpt{}
assert.Check(t, m.Set("type=bind,target=/foo,source=/foo,readonly=true"))
assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=true"))
assert.Check(t, m.values[0].ReadOnly)
m = MountOpt{}
assert.Check(t, m.Set("type=bind,target=/foo,source=/foo,readonly=0"))
assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=0"))
assert.Check(t, !m.values[0].ReadOnly)
}
func TestMountOptVolumeNoCopy(t *testing.T) {
var m MountOpt
assert.Check(t, m.Set("type=volume,target=/foo,volume-nocopy"))
assert.NilError(t, m.Set("type=volume,target=/foo,volume-nocopy"))
assert.Check(t, is.Equal("", m.values[0].Source))
m = MountOpt{}
assert.Check(t, m.Set("type=volume,target=/foo,source=foo"))
assert.NilError(t, m.Set("type=volume,target=/foo,source=foo"))
assert.Check(t, m.values[0].VolumeOptions == nil)
m = MountOpt{}
assert.Check(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy=true"))
assert.NilError(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy=true"))
assert.Check(t, m.values[0].VolumeOptions != nil)
assert.Check(t, m.values[0].VolumeOptions.NoCopy)
m = MountOpt{}
assert.Check(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy"))
assert.NilError(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy"))
assert.Check(t, m.values[0].VolumeOptions != nil)
assert.Check(t, m.values[0].VolumeOptions.NoCopy)
m = MountOpt{}
assert.Check(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy=1"))
assert.NilError(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy=1"))
assert.Check(t, m.values[0].VolumeOptions != nil)
assert.Check(t, m.values[0].VolumeOptions.NoCopy)
}
@ -162,7 +162,7 @@ func TestMountOptSetTmpfsNoError(t *testing.T) {
} {
var mount MountOpt
assert.Check(t, mount.Set(testcase))
assert.NilError(t, mount.Set(testcase))
mounts := mount.Value()
assert.Assert(t, is.Len(mounts, 1))

View File

@ -23,7 +23,7 @@ func TestNetworkOptLegacySyntax(t *testing.T) {
}
for _, tc := range testCases {
var network NetworkOpt
assert.Check(t, network.Set(tc.value))
assert.NilError(t, network.Set(tc.value))
assert.Check(t, is.DeepEqual(tc.expected, network.Value()))
}
}
@ -70,7 +70,7 @@ func TestNetworkOptCompleteSyntax(t *testing.T) {
}
for _, tc := range testCases {
var network NetworkOpt
assert.Check(t, network.Set(tc.value))
assert.NilError(t, network.Set(tc.value))
assert.Check(t, is.DeepEqual(tc.expected, network.Value()))
}
}

View File

@ -99,7 +99,7 @@ func TestPortOptValidSimpleSyntax(t *testing.T) {
}
for _, tc := range testCases {
var port PortOpt
assert.Check(t, port.Set(tc.value))
assert.NilError(t, port.Set(tc.value))
assert.Check(t, is.Len(port.Value(), len(tc.expected)))
for _, expectedPortConfig := range tc.expected {
assertContains(t, port.Value(), expectedPortConfig)
@ -190,7 +190,7 @@ func TestPortOptValidComplexSyntax(t *testing.T) {
}
for _, tc := range testCases {
var port PortOpt
assert.Check(t, port.Set(tc.value))
assert.NilError(t, port.Set(tc.value))
assert.Check(t, is.Len(port.Value(), len(tc.expected)))
for _, expectedPortConfig := range tc.expected {
assertContains(t, port.Value(), expectedPortConfig)

View File

@ -10,7 +10,7 @@ import (
func TestQuotedStringSetWithQuotes(t *testing.T) {
value := ""
qs := NewQuotedString(&value)
assert.Check(t, qs.Set(`"something"`))
assert.NilError(t, qs.Set(`"something"`))
assert.Check(t, is.Equal("something", qs.String()))
assert.Check(t, is.Equal("something", value))
}
@ -18,13 +18,13 @@ func TestQuotedStringSetWithQuotes(t *testing.T) {
func TestQuotedStringSetWithMismatchedQuotes(t *testing.T) {
value := ""
qs := NewQuotedString(&value)
assert.Check(t, qs.Set(`"something'`))
assert.NilError(t, qs.Set(`"something'`))
assert.Check(t, is.Equal(`"something'`, qs.String()))
}
func TestQuotedStringSetWithNoQuotes(t *testing.T) {
value := ""
qs := NewQuotedString(&value)
assert.Check(t, qs.Set("something"))
assert.NilError(t, qs.Set("something"))
assert.Check(t, is.Equal("something", qs.String()))
}

View File

@ -12,7 +12,7 @@ func TestSecretOptionsSimple(t *testing.T) {
var opt SecretOpt
testCase := "app-secret"
assert.Check(t, opt.Set(testCase))
assert.NilError(t, opt.Set(testCase))
reqs := opt.Value()
assert.Assert(t, is.Len(reqs, 1))
@ -27,7 +27,7 @@ func TestSecretOptionsSourceTarget(t *testing.T) {
var opt SecretOpt
testCase := "source=foo,target=testing"
assert.Check(t, opt.Set(testCase))
assert.NilError(t, opt.Set(testCase))
reqs := opt.Value()
assert.Assert(t, is.Len(reqs, 1))
@ -40,7 +40,7 @@ func TestSecretOptionsShorthand(t *testing.T) {
var opt SecretOpt
testCase := "src=foo,target=testing"
assert.Check(t, opt.Set(testCase))
assert.NilError(t, opt.Set(testCase))
reqs := opt.Value()
assert.Assert(t, is.Len(reqs, 1))
@ -52,7 +52,7 @@ func TestSecretOptionsCustomUidGid(t *testing.T) {
var opt SecretOpt
testCase := "source=foo,target=testing,uid=1000,gid=1001"
assert.Check(t, opt.Set(testCase))
assert.NilError(t, opt.Set(testCase))
reqs := opt.Value()
assert.Assert(t, is.Len(reqs, 1))
@ -67,7 +67,7 @@ func TestSecretOptionsCustomMode(t *testing.T) {
var opt SecretOpt
testCase := "source=foo,target=testing,uid=1000,gid=1001,mode=0444"
assert.Check(t, opt.Set(testCase))
assert.NilError(t, opt.Set(testCase))
reqs := opt.Value()
assert.Assert(t, is.Len(reqs, 1))

View File

@ -14,7 +14,7 @@ func TestParseJSONFunctions(t *testing.T) {
assert.NilError(t, err)
var b bytes.Buffer
assert.Check(t, tm.Execute(&b, map[string]string{"Ports": "0.0.0.0:2->8/udp"}))
assert.NilError(t, tm.Execute(&b, map[string]string{"Ports": "0.0.0.0:2->8/udp"}))
want := "\"0.0.0.0:2->8/udp\""
assert.Check(t, is.Equal(want, b.String()))
}
@ -24,7 +24,7 @@ func TestParseStringFunctions(t *testing.T) {
assert.NilError(t, err)
var b bytes.Buffer
assert.Check(t, tm.Execute(&b, "text:with:colon"))
assert.NilError(t, tm.Execute(&b, "text:with:colon"))
want := "text/with/colon"
assert.Check(t, is.Equal(want, b.String()))
}
@ -34,7 +34,7 @@ func TestNewParse(t *testing.T) {
assert.NilError(t, err)
var b bytes.Buffer
assert.Check(t, tm.Execute(&b, "string"))
assert.NilError(t, tm.Execute(&b, "string"))
want := "this is a string"
assert.Check(t, is.Equal(want, b.String()))
}
@ -70,13 +70,13 @@ func TestParseTruncateFunction(t *testing.T) {
t.Run("Non Empty Source Test with template: "+testCase.template, func(t *testing.T) {
var b bytes.Buffer
assert.Check(t, tm.Execute(&b, source))
assert.NilError(t, tm.Execute(&b, source))
assert.Check(t, is.Equal(testCase.expected, b.String()))
})
t.Run("Empty Source Test with template: "+testCase.template, func(t *testing.T) {
var c bytes.Buffer
assert.Check(t, tm.Execute(&c, ""))
assert.NilError(t, tm.Execute(&c, ""))
assert.Check(t, is.Equal("", c.String()))
})