From baf65a5502580a46090c7e523dfa3a3a075d7c8f Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 6 Mar 2018 14:44:13 -0500 Subject: [PATCH] Convert to assert.NilError Using: git grep -l '^\s\+assert\.Check(t, err)$' | \ xargs sed -i -e 's/^\(\s\+assert\)\.Check(t, err)$/\1.NilError(t, err)/' Signed-off-by: Daniel Nephin --- cli/command/bundlefile/bundlefile_test.go | 2 +- cli/command/cli_test.go | 6 ++-- cli/command/config/create_test.go | 2 +- cli/command/container/attach_test.go | 2 +- cli/command/container/opts_test.go | 2 +- cli/command/container/ps_test.go | 2 +- cli/command/formatter/trust_test.go | 4 +-- cli/command/idresolver/idresolver_test.go | 8 ++--- cli/command/image/history_test.go | 2 +- cli/command/image/inspect_test.go | 2 +- cli/command/image/list_test.go | 2 +- cli/command/image/load_test.go | 2 +- cli/command/image/prune_test.go | 2 +- cli/command/image/pull_test.go | 2 +- cli/command/image/trust_test.go | 2 +- cli/command/registry_test.go | 2 +- cli/command/secret/create_test.go | 2 +- .../service/generic_resource_opts_test.go | 2 +- cli/command/service/opts_test.go | 6 ++-- cli/command/service/update_test.go | 18 +++++----- .../stack/swarm/deploy_bundlefile_test.go | 2 +- .../stack/swarm/deploy_composefile_test.go | 2 +- cli/command/stack/swarm/deploy_test.go | 2 +- cli/command/swarm/ca_test.go | 2 +- cli/command/task/print_test.go | 12 +++---- cli/command/trust/helpers_test.go | 4 +-- cli/command/trust/key_generate_test.go | 26 +++++++------- cli/command/trust/key_load_test.go | 30 ++++++++-------- cli/command/trust/revoke_test.go | 2 +- cli/command/trust/sign_test.go | 36 +++++++++---------- cli/command/trust/signer_add_test.go | 14 ++++---- cli/command/trust/signer_remove_test.go | 2 +- cli/compose/convert/compose_test.go | 4 +-- cli/compose/convert/service_test.go | 36 +++++++++---------- cli/compose/convert/volume_test.go | 14 ++++---- .../interpolation/interpolation_test.go | 6 ++-- cli/compose/loader/loader_test.go | 2 +- cli/compose/loader/types_test.go | 6 ++-- cli/compose/loader/volume_test.go | 22 ++++++------ cli/compose/schema/schema_test.go | 4 +-- cli/compose/template/template_test.go | 16 ++++----- cli/config/credentials/native_store_test.go | 2 +- cli/flags/common_test.go | 4 +-- cli/trust/trust_test.go | 14 ++++---- cmd/docker/docker_test.go | 2 +- templates/templates_test.go | 8 ++--- 46 files changed, 173 insertions(+), 173 deletions(-) diff --git a/cli/command/bundlefile/bundlefile_test.go b/cli/command/bundlefile/bundlefile_test.go index 08bf896db6..7b3f9bad7b 100644 --- a/cli/command/bundlefile/bundlefile_test.go +++ b/cli/command/bundlefile/bundlefile_test.go @@ -26,7 +26,7 @@ func TestLoadFileV01Success(t *testing.T) { }`) bundle, err := LoadFile(reader) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal("0.1", bundle.Version)) assert.Check(t, is.Len(bundle.Services, 2)) } diff --git a/cli/command/cli_test.go b/cli/command/cli_test.go index 6e4f0cdf74..48a87d1bfb 100644 --- a/cli/command/cli_test.go +++ b/cli/command/cli_test.go @@ -163,7 +163,7 @@ func TestExperimentalCLI(t *testing.T) { cli := &DockerCli{client: apiclient, err: os.Stderr} cliconfig.SetDir(dir.Path()) err := cli.Initialize(flags.NewClientOptions()) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal(testcase.expectedExperimentalCLI, cli.ClientInfo().HasExperimental)) }) } @@ -266,7 +266,7 @@ func TestOrchestratorSwitch(t *testing.T) { options.Common.Orchestrator = testcase.flagOrchestrator } err := cli.Initialize(options) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal(testcase.expectedKubernetes, cli.ClientInfo().HasKubernetes())) assert.Check(t, is.Equal(testcase.expectedOrchestrator, string(cli.ClientInfo().Orchestrator))) }) @@ -334,7 +334,7 @@ func TestGetClientWithPassword(t *testing.T) { return } - assert.Check(t, err) + assert.NilError(t, err) }) } } diff --git a/cli/command/config/create_test.go b/cli/command/config/create_test.go index a21b59708e..06617934c2 100644 --- a/cli/command/config/create_test.go +++ b/cli/command/config/create_test.go @@ -83,7 +83,7 @@ func TestConfigCreateWithLabels(t *testing.T) { name := "foo" data, err := ioutil.ReadFile(filepath.Join("testdata", configDataFile)) - assert.Check(t, err) + assert.NilError(t, err) expected := swarm.ConfigSpec{ Annotations: swarm.Annotations{ diff --git a/cli/command/container/attach_test.go b/cli/command/container/attach_test.go index 0d519de65b..6c021f1b43 100644 --- a/cli/command/container/attach_test.go +++ b/cli/command/container/attach_test.go @@ -122,7 +122,7 @@ func TestGetExitStatus(t *testing.T) { } err := getExitStatus(errC, resultC) if testcase.expectedError == nil { - assert.Check(t, err) + assert.NilError(t, err) } else { assert.Check(t, is.Error(err, testcase.expectedError.Error())) } diff --git a/cli/command/container/opts_test.go b/cli/command/container/opts_test.go index b08f76c536..5d43409662 100644 --- a/cli/command/container/opts_test.go +++ b/cli/command/container/opts_test.go @@ -71,7 +71,7 @@ func parseMustError(t *testing.T, args string) { func mustParse(t *testing.T, args string) (*container.Config, *container.HostConfig) { config, hostConfig, _, err := parseRun(append(strings.Split(args, " "), "ubuntu", "bash")) - assert.Check(t, err) + assert.NilError(t, err) return config, hostConfig } diff --git a/cli/command/container/ps_test.go b/cli/command/container/ps_test.go index a781c1f590..42e36f3578 100644 --- a/cli/command/container/ps_test.go +++ b/cli/command/container/ps_test.go @@ -102,7 +102,7 @@ func TestBuildContainerListOptions(t *testing.T) { for _, c := range contexts { options, err := buildContainerListOptions(c.psOpts) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal(c.expectedAll, options.All)) assert.Check(t, is.Equal(c.expectedSize, options.Size)) diff --git a/cli/command/formatter/trust_test.go b/cli/command/formatter/trust_test.go index bd18c97b5a..f28fd94300 100644 --- a/cli/command/formatter/trust_test.go +++ b/cli/command/formatter/trust_test.go @@ -153,7 +153,7 @@ func TestTrustTagContextEmptyWrite(t *testing.T) { out := bytes.NewBufferString("") emptyCase.context.Output = out err := TrustTagWrite(emptyCase.context, emptySignedTags) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal(emptyCase.expected, out.String())) } @@ -172,7 +172,7 @@ func TestSignerInfoContextEmptyWrite(t *testing.T) { out := bytes.NewBufferString("") emptyCase.context.Output = out err := SignerInfoWrite(emptyCase.context, emptySignerInfo) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal(emptyCase.expected, out.String())) } diff --git a/cli/command/idresolver/idresolver_test.go b/cli/command/idresolver/idresolver_test.go index b64fca7c25..5550a9a4ed 100644 --- a/cli/command/idresolver/idresolver_test.go +++ b/cli/command/idresolver/idresolver_test.go @@ -41,7 +41,7 @@ func TestResolveWithNoResolveOption(t *testing.T) { idResolver := New(cli, true) id, err := idResolver.Resolve(context.Background(), swarm.Node{}, "nodeID") - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal("nodeID", id)) assert.Check(t, !resolved) } @@ -60,7 +60,7 @@ func TestResolveWithCache(t *testing.T) { ctx := context.Background() for i := 0; i < 2; i++ { id, err := idResolver.Resolve(ctx, swarm.Node{}, "nodeID") - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal("node-foo", id)) } @@ -104,7 +104,7 @@ func TestResolveNode(t *testing.T) { idResolver := New(cli, false) id, err := idResolver.Resolve(ctx, swarm.Node{}, tc.nodeID) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal(tc.expectedID, id)) } } @@ -139,7 +139,7 @@ func TestResolveService(t *testing.T) { idResolver := New(cli, false) id, err := idResolver.Resolve(ctx, swarm.Service{}, tc.serviceID) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal(tc.expectedID, id)) } } diff --git a/cli/command/image/history_test.go b/cli/command/image/history_test.go index 1005e87486..ce03c8c64d 100644 --- a/cli/command/image/history_test.go +++ b/cli/command/image/history_test.go @@ -91,7 +91,7 @@ func TestNewHistoryCommandSuccess(t *testing.T) { cmd.SetOutput(ioutil.Discard) cmd.SetArgs(tc.args) err := cmd.Execute() - assert.Check(t, err) + assert.NilError(t, err) actual := cli.OutBuffer().String() golden.Assert(t, actual, fmt.Sprintf("history-command-success.%s.golden", tc.name)) } diff --git a/cli/command/image/inspect_test.go b/cli/command/image/inspect_test.go index 76f47ae003..4bf0547416 100644 --- a/cli/command/image/inspect_test.go +++ b/cli/command/image/inspect_test.go @@ -81,7 +81,7 @@ func TestNewInspectCommandSuccess(t *testing.T) { cmd.SetOutput(ioutil.Discard) cmd.SetArgs(tc.args) err := cmd.Execute() - assert.Check(t, err) + assert.NilError(t, err) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("inspect-command-success.%s.golden", tc.name)) assert.Check(t, is.Equal(imageInspectInvocationCount, tc.imageCount)) } diff --git a/cli/command/image/list_test.go b/cli/command/image/list_test.go index 3df7c4b75a..f4ce847262 100644 --- a/cli/command/image/list_test.go +++ b/cli/command/image/list_test.go @@ -85,7 +85,7 @@ func TestNewImagesCommandSuccess(t *testing.T) { cmd.SetOutput(ioutil.Discard) cmd.SetArgs(tc.args) err := cmd.Execute() - assert.Check(t, err) + assert.NilError(t, err) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("list-command-success.%s.golden", tc.name)) } } diff --git a/cli/command/image/load_test.go b/cli/command/image/load_test.go index 69ff76d891..d3ec89e36c 100644 --- a/cli/command/image/load_test.go +++ b/cli/command/image/load_test.go @@ -95,7 +95,7 @@ func TestNewLoadCommandSuccess(t *testing.T) { cmd.SetOutput(ioutil.Discard) cmd.SetArgs(tc.args) err := cmd.Execute() - assert.Check(t, err) + assert.NilError(t, err) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("load-command-success.%s.golden", tc.name)) } } diff --git a/cli/command/image/prune_test.go b/cli/command/image/prune_test.go index 26622db6ff..9c03d83d72 100644 --- a/cli/command/image/prune_test.go +++ b/cli/command/image/prune_test.go @@ -88,7 +88,7 @@ func TestNewPruneCommandSuccess(t *testing.T) { cmd.SetOutput(ioutil.Discard) cmd.SetArgs(tc.args) err := cmd.Execute() - assert.Check(t, err) + assert.NilError(t, err) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("prune-command-success.%s.golden", tc.name)) } } diff --git a/cli/command/image/pull_test.go b/cli/command/image/pull_test.go index ba0048fdbb..7770e32952 100644 --- a/cli/command/image/pull_test.go +++ b/cli/command/image/pull_test.go @@ -73,7 +73,7 @@ func TestNewPullCommandSuccess(t *testing.T) { cmd.SetOutput(ioutil.Discard) cmd.SetArgs(tc.args) err := cmd.Execute() - assert.Check(t, err) + assert.NilError(t, err) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("pull-command-success.%s.golden", tc.name)) } } diff --git a/cli/command/image/trust_test.go b/cli/command/image/trust_test.go index 92b0c49cb1..85670b8518 100644 --- a/cli/command/image/trust_test.go +++ b/cli/command/image/trust_test.go @@ -64,7 +64,7 @@ func TestNonOfficialTrustServer(t *testing.T) { func TestAddTargetToAllSignableRolesError(t *testing.T) { tmpDir, err := ioutil.TempDir("", "notary-test-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{}) diff --git a/cli/command/registry_test.go b/cli/command/registry_test.go index 0c56c79737..33407b9f44 100644 --- a/cli/command/registry_test.go +++ b/cli/command/registry_test.go @@ -140,7 +140,7 @@ func TestGetDefaultAuthConfig(t *testing.T) { assert.Check(t, err != nil) assert.Check(t, is.Equal(tc.expectedErr, err.Error())) } else { - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(tc.expectedAuthConfig, *authconfig)) } } diff --git a/cli/command/secret/create_test.go b/cli/command/secret/create_test.go index 33b077b2d1..b6a8dc22d2 100644 --- a/cli/command/secret/create_test.go +++ b/cli/command/secret/create_test.go @@ -52,7 +52,7 @@ func TestSecretCreateErrors(t *testing.T) { func TestSecretCreateWithName(t *testing.T) { name := "foo" data, err := ioutil.ReadFile(filepath.Join("testdata", secretDataFile)) - assert.Check(t, err) + assert.NilError(t, err) expected := swarm.SecretSpec{ Annotations: swarm.Annotations{ diff --git a/cli/command/service/generic_resource_opts_test.go b/cli/command/service/generic_resource_opts_test.go index 3d64a99857..ffc7f4ca64 100644 --- a/cli/command/service/generic_resource_opts_test.go +++ b/cli/command/service/generic_resource_opts_test.go @@ -18,6 +18,6 @@ func TestValidateSingleGenericResource(t *testing.T) { for _, v := range correct { _, err := ValidateSingleGenericResource(v) - assert.Check(t, err) + assert.NilError(t, err) } } diff --git a/cli/command/service/opts_test.go b/cli/command/service/opts_test.go index 8127d61d68..8c5af59b7a 100644 --- a/cli/command/service/opts_test.go +++ b/cli/command/service/opts_test.go @@ -61,7 +61,7 @@ func TestHealthCheckOptionsToHealthConfig(t *testing.T) { retries: 10, } config, err := opt.toHealthConfig() - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(&container.HealthConfig{ Test: []string{"CMD-SHELL", "curl"}, Interval: time.Second, @@ -76,7 +76,7 @@ func TestHealthCheckOptionsToHealthConfigNoHealthcheck(t *testing.T) { noHealthcheck: true, } config, err := opt.toHealthConfig() - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(&container.HealthConfig{ Test: []string{"NONE"}, }, config)) @@ -123,7 +123,7 @@ func TestResourceOptionsToResourceRequirements(t *testing.T) { for _, opt := range correctOptions { r, err := opt.ToResourceRequirements() - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Len(r.Reservations.GenericResources, len(opt.resGenericResources))) } diff --git a/cli/command/service/update_test.go b/cli/command/service/update_test.go index a4cc53385c..863d612a48 100644 --- a/cli/command/service/update_test.go +++ b/cli/command/service/update_test.go @@ -244,7 +244,7 @@ func TestUpdatePorts(t *testing.T) { } err := updatePorts(flags, &portConfigs) - assert.Check(t, err) + assert.NilError(t, err) assert.Assert(t, is.Len(portConfigs, 2)) // Do a sort to have the order (might have changed by map) targetPorts := []int{int(portConfigs[0].TargetPort), int(portConfigs[1].TargetPort)} @@ -268,7 +268,7 @@ func TestUpdatePortsDuplicate(t *testing.T) { } err := updatePorts(flags, &portConfigs) - assert.Check(t, err) + assert.NilError(t, err) assert.Assert(t, is.Len(portConfigs, 1)) assert.Check(t, is.Equal(uint32(80), portConfigs[0].TargetPort)) } @@ -346,7 +346,7 @@ func TestUpdateHealthcheckTable(t *testing.T) { if c.err != "" { assert.Check(t, is.Error(err, c.err)) } else { - assert.Check(t, err) + assert.NilError(t, err) if !reflect.DeepEqual(cspec.Healthcheck, c.expected) { t.Errorf("incorrect result for test %d, expected health config:\n\t%#v\ngot:\n\t%#v", i, c.expected, cspec.Healthcheck) } @@ -369,7 +369,7 @@ func TestUpdateHosts(t *testing.T) { expected := []string{"1.2.3.4 example.com", "4.3.2.1 example.org", "2001:db8:abc8::1 ipv6.net"} err := updateHosts(flags, &hosts) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, hosts)) } @@ -381,7 +381,7 @@ func TestUpdateHostsPreservesOrder(t *testing.T) { hosts := []string{} err := updateHosts(flags, &hosts) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual([]string{"127.0.0.2 foobar", "127.0.0.1 foobar", "127.0.0.3 foobar"}, hosts)) } @@ -403,7 +403,7 @@ func TestUpdatePortsRmWithProtocol(t *testing.T) { } err := updatePorts(flags, &portConfigs) - assert.Check(t, err) + assert.NilError(t, err) assert.Assert(t, is.Len(portConfigs, 2)) assert.Check(t, is.Equal(uint32(81), portConfigs[0].TargetPort)) assert.Check(t, is.Equal(uint32(82), portConfigs[1].TargetPort)) @@ -460,7 +460,7 @@ func TestUpdateSecretUpdateInPlace(t *testing.T) { updatedSecrets, err := getUpdatedSecrets(apiClient, flags, secrets) - assert.Check(t, err) + assert.NilError(t, err) assert.Assert(t, is.Len(updatedSecrets, 1)) assert.Check(t, is.Equal("tn9qiblgnuuut11eufquw5dev", updatedSecrets[0].SecretID)) assert.Check(t, is.Equal("foo", updatedSecrets[0].SecretName)) @@ -640,7 +640,7 @@ func TestUpdateNetworks(t *testing.T) { err = flags.Set(flagNetworkRemove, "id999") assert.NilError(t, err) err = updateService(ctx, client, flags, &svc) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id555"}}, svc.TaskTemplate.Networks)) flags = newUpdateCommand(nil).Flags() @@ -649,6 +649,6 @@ func TestUpdateNetworks(t *testing.T) { err = flags.Set(flagNetworkRemove, "aaa-network") assert.NilError(t, err) err = updateService(ctx, client, flags, &svc) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id999"}}, svc.TaskTemplate.Networks)) } diff --git a/cli/command/stack/swarm/deploy_bundlefile_test.go b/cli/command/stack/swarm/deploy_bundlefile_test.go index cc1535fc9b..4e66caabed 100644 --- a/cli/command/stack/swarm/deploy_bundlefile_test.go +++ b/cli/command/stack/swarm/deploy_bundlefile_test.go @@ -45,6 +45,6 @@ func TestLoadBundlefile(t *testing.T) { path := filepath.Join("testdata", "bundlefile_with_two_services.dab") bundleFile, err := loadBundlefile(buf, namespace, path) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal(len(bundleFile.Services), 2)) } diff --git a/cli/command/stack/swarm/deploy_composefile_test.go b/cli/command/stack/swarm/deploy_composefile_test.go index a864c5b658..91c318cd63 100644 --- a/cli/command/stack/swarm/deploy_composefile_test.go +++ b/cli/command/stack/swarm/deploy_composefile_test.go @@ -56,7 +56,7 @@ func TestValidateExternalNetworks(t *testing.T) { networks := []string{testcase.network} err := validateExternalNetworks(context.Background(), fakeClient, networks) if testcase.expectedMsg == "" { - assert.Check(t, err) + assert.NilError(t, err) } else { assert.ErrorContains(t, err, testcase.expectedMsg) } diff --git a/cli/command/stack/swarm/deploy_test.go b/cli/command/stack/swarm/deploy_test.go index 15199c3731..3fdbbdbee7 100644 --- a/cli/command/stack/swarm/deploy_test.go +++ b/cli/command/stack/swarm/deploy_test.go @@ -94,7 +94,7 @@ func TestServiceUpdateResolveImageChanged(t *testing.T) { }, } err := deployServices(ctx, client, spec, namespace, false, ResolveImageChanged) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal(testcase.expectedQueryRegistry, receivedOptions.QueryRegistry)) assert.Check(t, is.Equal(testcase.expectedImage, receivedService.TaskTemplate.ContainerSpec.Image)) diff --git a/cli/command/swarm/ca_test.go b/cli/command/swarm/ca_test.go index 72b20e61e4..37e18655a9 100644 --- a/cli/command/swarm/ca_test.go +++ b/cli/command/swarm/ca_test.go @@ -40,7 +40,7 @@ func TestDisplayTrustRootNoRoot(t *testing.T) { func TestDisplayTrustRootInvalidFlags(t *testing.T) { // we need an actual PEMfile to test tmpfile, err := ioutil.TempFile("", "pemfile") - assert.Check(t, err) + assert.NilError(t, err) defer os.Remove(tmpfile.Name()) tmpfile.Write([]byte(` -----BEGIN CERTIFICATE----- diff --git a/cli/command/task/print_test.go b/cli/command/task/print_test.go index 7803b799ef..731d2de16f 100644 --- a/cli/command/task/print_test.go +++ b/cli/command/task/print_test.go @@ -24,7 +24,7 @@ func TestTaskPrintWithQuietOption(t *testing.T) { cli := test.NewFakeCli(apiClient) tasks := []swarm.Task{*Task(TaskID("id-foo"))} err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, formatter.TableFormatKey) - assert.Check(t, err) + assert.NilError(t, err) golden.Assert(t, cli.OutBuffer().String(), "task-print-with-quiet-option.golden") } @@ -38,7 +38,7 @@ func TestTaskPrintWithNoTruncOption(t *testing.T) { *Task(TaskID("id-foo-yov6omdek8fg3k5stosyp2m50")), } err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .ID }}") - assert.Check(t, err) + assert.NilError(t, err) golden.Assert(t, cli.OutBuffer().String(), "task-print-with-no-trunc-option.golden") } @@ -52,7 +52,7 @@ func TestTaskPrintWithGlobalService(t *testing.T) { *Task(TaskServiceID("service-id-foo"), TaskNodeID("node-id-bar"), TaskSlot(0)), } err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .Name }}") - assert.Check(t, err) + assert.NilError(t, err) golden.Assert(t, cli.OutBuffer().String(), "task-print-with-global-service.golden") } @@ -66,7 +66,7 @@ func TestTaskPrintWithReplicatedService(t *testing.T) { *Task(TaskServiceID("service-id-foo"), TaskSlot(1)), } err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .Name }}") - assert.Check(t, err) + assert.NilError(t, err) golden.Assert(t, cli.OutBuffer().String(), "task-print-with-replicated-service.golden") } @@ -102,7 +102,7 @@ func TestTaskPrintWithIndentation(t *testing.T) { ), } err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, formatter.TableFormatKey) - assert.Check(t, err) + assert.NilError(t, err) golden.Assert(t, cli.OutBuffer().String(), "task-print-with-indentation.golden") } @@ -123,6 +123,6 @@ func TestTaskPrintWithResolution(t *testing.T) { *Task(TaskServiceID("service-id-foo"), TaskSlot(1)), } err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .Name }} {{ .Node }}") - assert.Check(t, err) + assert.NilError(t, err) golden.Assert(t, cli.OutBuffer().String(), "task-print-with-resolution.golden") } diff --git a/cli/command/trust/helpers_test.go b/cli/command/trust/helpers_test.go index 8cd189c256..ba70df6e39 100644 --- a/cli/command/trust/helpers_test.go +++ b/cli/command/trust/helpers_test.go @@ -14,11 +14,11 @@ import ( func TestGetOrGenerateNotaryKeyAndInitRepo(t *testing.T) { tmpDir, err := ioutil.TempDir("", "notary-test-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{}) - assert.Check(t, err) + assert.NilError(t, err) err = getOrGenerateRootKeyAndInitRepo(notaryRepo) assert.Check(t, is.Error(err, "client is offline")) diff --git a/cli/command/trust/key_generate_test.go b/cli/command/trust/key_generate_test.go index eadf43ea21..38c34863e5 100644 --- a/cli/command/trust/key_generate_test.go +++ b/cli/command/trust/key_generate_test.go @@ -36,7 +36,7 @@ func TestTrustKeyGenerateErrors(t *testing.T) { } tmpDir, err := ioutil.TempDir("", "docker-key-generate-test-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) config.SetDir(tmpDir) @@ -51,11 +51,11 @@ func TestTrustKeyGenerateErrors(t *testing.T) { func TestGenerateKeySuccess(t *testing.T) { pubKeyCWD, err := ioutil.TempDir("", "pub-keys-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(pubKeyCWD) privKeyStorageDir, err := ioutil.TempDir("", "priv-keys-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(privKeyStorageDir) passwd := "password" @@ -63,10 +63,10 @@ func TestGenerateKeySuccess(t *testing.T) { // generate a single key keyName := "alice" privKeyFileStore, err := trustmanager.NewKeyFileStore(privKeyStorageDir, cannedPasswordRetriever) - assert.Check(t, err) + assert.NilError(t, err) pubKeyPEM, err := generateKeyAndOutputPubPEM(keyName, privKeyFileStore) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal(keyName, pubKeyPEM.Headers["role"])) // the default GUN is empty @@ -77,10 +77,10 @@ func TestGenerateKeySuccess(t *testing.T) { // check that an appropriate ~//private/.key file exists expectedPrivKeyDir := filepath.Join(privKeyStorageDir, notary.PrivDir) _, err = os.Stat(expectedPrivKeyDir) - assert.Check(t, err) + assert.NilError(t, err) keyFiles, err := ioutil.ReadDir(expectedPrivKeyDir) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Len(keyFiles, 1)) privKeyFilePath := filepath.Join(expectedPrivKeyDir, keyFiles[0].Name()) @@ -96,28 +96,28 @@ func TestGenerateKeySuccess(t *testing.T) { assert.Check(t, is.Equal("ENCRYPTED PRIVATE KEY", privKeyPEM.Type)) // check that the passphrase matches _, err = tufutils.ParsePKCS8ToTufKey(privKeyPEM.Bytes, []byte(passwd)) - assert.Check(t, err) + assert.NilError(t, err) // check that the public key exists at the correct path if we use the helper: returnedPath, err := writePubKeyPEMToDir(pubKeyPEM, keyName, pubKeyCWD) - assert.Check(t, err) + assert.NilError(t, err) expectedPubKeyPath := filepath.Join(pubKeyCWD, keyName+".pub") assert.Check(t, is.Equal(returnedPath, expectedPubKeyPath)) _, err = os.Stat(expectedPubKeyPath) - assert.Check(t, err) + assert.NilError(t, err) // check that the public key is the only file output in CWD cwdKeyFiles, err := ioutil.ReadDir(pubKeyCWD) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Len(cwdKeyFiles, 1)) } func TestValidateKeyArgs(t *testing.T) { pubKeyCWD, err := ioutil.TempDir("", "pub-keys-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(pubKeyCWD) err = validateKeyArgs("a", pubKeyCWD) - assert.Check(t, err) + assert.NilError(t, err) err = validateKeyArgs("a/b", pubKeyCWD) assert.Error(t, err, "key name \"a/b\" must start with lowercase alphanumeric characters and can include \"-\" or \"_\" after the first character") diff --git a/cli/command/trust/key_load_test.go b/cli/command/trust/key_load_test.go index 12b7f84d48..3cbbf43d9d 100644 --- a/cli/command/trust/key_load_test.go +++ b/cli/command/trust/key_load_test.go @@ -51,7 +51,7 @@ func TestTrustKeyLoadErrors(t *testing.T) { }, } tmpDir, err := ioutil.TempDir("", "docker-key-load-test-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) config.SetDir(tmpDir) @@ -118,24 +118,24 @@ func TestLoadKeyFromPath(t *testing.T) { func testLoadKeyFromPath(t *testing.T, privKeyID string, privKeyFixture []byte) { privKeyDir, err := ioutil.TempDir("", "key-load-test-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(privKeyDir) privKeyFilepath := filepath.Join(privKeyDir, "privkey.pem") assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, notary.PrivNoExecPerms)) keyStorageDir, err := ioutil.TempDir("", "loaded-keys-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(keyStorageDir) passwd := "password" cannedPasswordRetriever := passphrase.ConstantRetriever(passwd) keyFileStore, err := storage.NewPrivateKeyFileStorage(keyStorageDir, notary.KeyExtension) - assert.Check(t, err) + assert.NilError(t, err) privKeyImporters := []trustmanager.Importer{keyFileStore} // get the privKeyBytes privKeyBytes, err := getPrivKeyBytesFromPath(privKeyFilepath) - assert.Check(t, err) + assert.NilError(t, err) // import the key to our keyStorageDir assert.Check(t, loadPrivKeyBytesToStore(privKeyBytes, privKeyImporters, privKeyFilepath, "signer-name", cannedPasswordRetriever)) @@ -143,7 +143,7 @@ func testLoadKeyFromPath(t *testing.T, privKeyID string, privKeyFixture []byte) // check that the appropriate ~//private/.key file exists expectedImportKeyPath := filepath.Join(keyStorageDir, notary.PrivDir, privKeyID+"."+notary.KeyExtension) _, err = os.Stat(expectedImportKeyPath) - assert.Check(t, err) + assert.NilError(t, err) // verify the key content from, _ := os.OpenFile(expectedImportKeyPath, os.O_RDONLY, notary.PrivExecPerms) @@ -157,7 +157,7 @@ func testLoadKeyFromPath(t *testing.T, privKeyID string, privKeyFixture []byte) assert.Check(t, is.Equal("ENCRYPTED PRIVATE KEY", keyPEM.Type)) decryptedKey, err := tufutils.ParsePKCS8ToTufKey(keyPEM.Bytes, []byte(passwd)) - assert.Check(t, err) + assert.NilError(t, err) fixturePEM, _ := pem.Decode(privKeyFixture) assert.Check(t, is.DeepEqual(fixturePEM.Bytes, decryptedKey.Private())) } @@ -172,13 +172,13 @@ func TestLoadKeyTooPermissive(t *testing.T) { func testLoadKeyTooPermissive(t *testing.T, privKeyFixture []byte) { privKeyDir, err := ioutil.TempDir("", "key-load-test-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(privKeyDir) privKeyFilepath := filepath.Join(privKeyDir, "privkey477.pem") assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0477)) keyStorageDir, err := ioutil.TempDir("", "loaded-keys-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(keyStorageDir) // import the key to our keyStorageDir @@ -204,13 +204,13 @@ func testLoadKeyTooPermissive(t *testing.T, privKeyFixture []byte) { assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0400)) _, err = getPrivKeyBytesFromPath(privKeyFilepath) - assert.Check(t, err) + assert.NilError(t, err) privKeyFilepath = filepath.Join(privKeyDir, "privkey600.pem") assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0600)) _, err = getPrivKeyBytesFromPath(privKeyFilepath) - assert.Check(t, err) + assert.NilError(t, err) } var pubKeyFixture = []byte(`-----BEGIN PUBLIC KEY----- @@ -220,22 +220,22 @@ H3nzy2O6Q/ct4BjOBKa+WCdRtPo78bA+C/7t81ADQO8Jqaj59W50rwoqDQ== func TestLoadPubKeyFailure(t *testing.T) { pubKeyDir, err := ioutil.TempDir("", "key-load-test-pubkey-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(pubKeyDir) pubKeyFilepath := filepath.Join(pubKeyDir, "pubkey.pem") assert.Check(t, ioutil.WriteFile(pubKeyFilepath, pubKeyFixture, notary.PrivNoExecPerms)) keyStorageDir, err := ioutil.TempDir("", "loaded-keys-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(keyStorageDir) passwd := "password" cannedPasswordRetriever := passphrase.ConstantRetriever(passwd) keyFileStore, err := storage.NewPrivateKeyFileStorage(keyStorageDir, notary.KeyExtension) - assert.Check(t, err) + assert.NilError(t, err) privKeyImporters := []trustmanager.Importer{keyFileStore} pubKeyBytes, err := getPrivKeyBytesFromPath(pubKeyFilepath) - assert.Check(t, err) + assert.NilError(t, err) // import the key to our keyStorageDir - it should fail err = loadPrivKeyBytesToStore(pubKeyBytes, privKeyImporters, pubKeyFilepath, "signer-name", cannedPasswordRetriever) diff --git a/cli/command/trust/revoke_test.go b/cli/command/trust/revoke_test.go index 25d579e452..f3f94b96b6 100644 --- a/cli/command/trust/revoke_test.go +++ b/cli/command/trust/revoke_test.go @@ -136,7 +136,7 @@ func TestNewRevokeTrustAllSigConfirmation(t *testing.T) { func TestGetSignableRolesForTargetAndRemoveError(t *testing.T) { tmpDir, err := ioutil.TempDir("", "notary-test-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{}) diff --git a/cli/command/trust/sign_test.go b/cli/command/trust/sign_test.go index 4cc338f10d..e8eb168b8e 100644 --- a/cli/command/trust/sign_test.go +++ b/cli/command/trust/sign_test.go @@ -60,7 +60,7 @@ func TestTrustSignCommandErrors(t *testing.T) { } // change to a tmpdir tmpDir, err := ioutil.TempDir("", "docker-sign-test-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) config.SetDir(tmpDir) for _, tc := range testCases { @@ -83,15 +83,15 @@ func TestTrustSignCommandOfflineErrors(t *testing.T) { func TestGetOrGenerateNotaryKey(t *testing.T) { tmpDir, err := ioutil.TempDir("", "notary-test-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{}) - assert.Check(t, err) + assert.NilError(t, err) // repo is empty, try making a root key rootKeyA, err := getOrGenerateNotaryKey(notaryRepo, data.CanonicalRootRole) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, rootKeyA != nil) // we should only have one newly generated key @@ -101,7 +101,7 @@ func TestGetOrGenerateNotaryKey(t *testing.T) { // this time we should get back the same key if we ask for another root key rootKeyB, err := getOrGenerateNotaryKey(notaryRepo, data.CanonicalRootRole) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, rootKeyB != nil) // we should only have one newly generated key @@ -114,7 +114,7 @@ func TestGetOrGenerateNotaryKey(t *testing.T) { // Now also try with a delegation key releasesKey, err := getOrGenerateNotaryKey(notaryRepo, data.RoleName(trust.ReleasesRole)) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, releasesKey != nil) // we should now have two keys @@ -128,20 +128,20 @@ func TestGetOrGenerateNotaryKey(t *testing.T) { func TestAddStageSigners(t *testing.T) { tmpDir, err := ioutil.TempDir("", "notary-test-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{}) - assert.Check(t, err) + assert.NilError(t, err) // stage targets/user userRole := data.RoleName("targets/user") userKey := data.NewPublicKey("algoA", []byte("a")) err = addStagedSigner(notaryRepo, userRole, []data.PublicKey{userKey}) - assert.Check(t, err) + assert.NilError(t, err) // check the changelist for four total changes: two on targets/releases and two on targets/user cl, err := notaryRepo.GetChangelist() - assert.Check(t, err) + assert.NilError(t, err) changeList := cl.List() assert.Check(t, is.Len(changeList, 4)) // ordering is determinstic: @@ -213,11 +213,11 @@ func TestAddStageSigners(t *testing.T) { func TestGetSignedManifestHashAndSize(t *testing.T) { tmpDir, err := ioutil.TempDir("", "notary-test-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{}) - assert.Check(t, err) + assert.NilError(t, err) target := &client.Target{} target.Hashes, target.Length, err = getSignedManifestHashAndSize(notaryRepo, "test") assert.Check(t, is.Error(err, "client is offline")) @@ -241,11 +241,11 @@ func TestGetReleasedTargetHashAndSize(t *testing.T) { func TestCreateTarget(t *testing.T) { tmpDir, err := ioutil.TempDir("", "notary-test-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{}) - assert.Check(t, err) + assert.NilError(t, err) _, err = createTarget(notaryRepo, "") assert.Check(t, is.Error(err, "No tag specified")) _, err = createTarget(notaryRepo, "1") @@ -254,11 +254,11 @@ func TestCreateTarget(t *testing.T) { func TestGetExistingSignatureInfoForReleasedTag(t *testing.T) { tmpDir, err := ioutil.TempDir("", "notary-test-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{}) - assert.Check(t, err) + assert.NilError(t, err) _, err = getExistingSignatureInfoForReleasedTag(notaryRepo, "test") assert.Check(t, is.Error(err, "client is offline")) } @@ -274,7 +274,7 @@ func TestPrettyPrintExistingSignatureInfo(t *testing.T) { func TestSignCommandChangeListIsCleanedOnError(t *testing.T) { tmpDir, err := ioutil.TempDir("", "docker-sign-test-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) config.SetDir(tmpDir) @@ -288,7 +288,7 @@ func TestSignCommandChangeListIsCleanedOnError(t *testing.T) { assert.Assert(t, is.ErrorContains(err, "")) notaryRepo, err := client.NewFileCachedRepository(tmpDir, "docker.io/library/ubuntu", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{}) - assert.Check(t, err) + assert.NilError(t, err) cl, err := notaryRepo.GetChangelist() assert.NilError(t, err) assert.Check(t, is.Equal(len(cl.List()), 0)) diff --git a/cli/command/trust/signer_add_test.go b/cli/command/trust/signer_add_test.go index e691b10f5c..af1921734b 100644 --- a/cli/command/trust/signer_add_test.go +++ b/cli/command/trust/signer_add_test.go @@ -51,7 +51,7 @@ func TestTrustSignerAddErrors(t *testing.T) { }, } tmpDir, err := ioutil.TempDir("", "docker-sign-test-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) config.SetDir(tmpDir) @@ -67,12 +67,12 @@ func TestTrustSignerAddErrors(t *testing.T) { func TestSignerAddCommandNoTargetsKey(t *testing.T) { tmpDir, err := ioutil.TempDir("", "docker-sign-test-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) config.SetDir(tmpDir) tmpfile, err := ioutil.TempFile("", "pemfile") - assert.Check(t, err) + assert.NilError(t, err) defer os.Remove(tmpfile.Name()) cli := test.NewFakeCli(&fakeClient{}) @@ -86,7 +86,7 @@ func TestSignerAddCommandNoTargetsKey(t *testing.T) { func TestSignerAddCommandBadKeyPath(t *testing.T) { tmpDir, err := ioutil.TempDir("", "docker-sign-test-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) config.SetDir(tmpDir) @@ -101,12 +101,12 @@ func TestSignerAddCommandBadKeyPath(t *testing.T) { func TestSignerAddCommandInvalidRepoName(t *testing.T) { tmpDir, err := ioutil.TempDir("", "docker-sign-test-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) config.SetDir(tmpDir) pubKeyDir, err := ioutil.TempDir("", "key-load-test-pubkey-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(pubKeyDir) pubKeyFilepath := filepath.Join(pubKeyDir, "pubkey.pem") assert.Check(t, ioutil.WriteFile(pubKeyFilepath, pubKeyFixture, notary.PrivNoExecPerms)) @@ -130,7 +130,7 @@ func TestIngestPublicKeys(t *testing.T) { assert.Check(t, is.Error(err, "unable to read public key from file: open foo: no such file or directory")) // Call with real file path tmpfile, err := ioutil.TempFile("", "pemfile") - assert.Check(t, err) + assert.NilError(t, err) defer os.Remove(tmpfile.Name()) _, err = ingestPublicKeys([]string{tmpfile.Name()}) assert.Check(t, is.Error(err, fmt.Sprintf("could not parse public key from file: %s: no valid public key found", tmpfile.Name()))) diff --git a/cli/command/trust/signer_remove_test.go b/cli/command/trust/signer_remove_test.go index 4f625c1dbb..d283d650a8 100644 --- a/cli/command/trust/signer_remove_test.go +++ b/cli/command/trust/signer_remove_test.go @@ -90,7 +90,7 @@ func TestRemoveLastSignerWarning(t *testing.T) { cli.SetNotaryClient(getLoadedNotaryRepository) err := removeSigner(cli, signerRemoveOptions{signer: "alice", repos: []string{"signed-repo"}, forceYes: false}) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Contains(cli.OutBuffer().String(), "The signer \"alice\" signed the last released version of signed-repo. "+ "Removing this signer will make signed-repo unpullable. "+ diff --git a/cli/compose/convert/compose_test.go b/cli/compose/convert/compose_test.go index 2963b96c01..a2ff2f1723 100644 --- a/cli/compose/convert/compose_test.go +++ b/cli/compose/convert/compose_test.go @@ -121,7 +121,7 @@ func TestSecrets(t *testing.T) { } specs, err := Secrets(namespace, source) - assert.Check(t, err) + assert.NilError(t, err) assert.Assert(t, is.Len(specs, 1)) secret := specs[0] assert.Check(t, is.Equal("foo_one", secret.Name)) @@ -152,7 +152,7 @@ func TestConfigs(t *testing.T) { } specs, err := Configs(namespace, source) - assert.Check(t, err) + assert.NilError(t, err) assert.Assert(t, is.Len(specs, 1)) config := specs[0] assert.Check(t, is.Equal("foo_one", config.Name)) diff --git a/cli/compose/convert/service_test.go b/cli/compose/convert/service_test.go index e3c72b68db..b4de57a25d 100644 --- a/cli/compose/convert/service_test.go +++ b/cli/compose/convert/service_test.go @@ -20,7 +20,7 @@ import ( func TestConvertRestartPolicyFromNone(t *testing.T) { policy, err := convertRestartPolicy("no", nil) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual((*swarm.RestartPolicy)(nil), policy)) } @@ -34,7 +34,7 @@ func TestConvertRestartPolicyFromAlways(t *testing.T) { expected := &swarm.RestartPolicy{ Condition: swarm.RestartPolicyConditionAny, } - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, policy)) } @@ -45,7 +45,7 @@ func TestConvertRestartPolicyFromFailure(t *testing.T) { Condition: swarm.RestartPolicyConditionOnFailure, MaxAttempts: &attempts, } - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, policy)) } @@ -84,7 +84,7 @@ func TestConvertResourcesFull(t *testing.T) { }, } resources, err := convertResources(source) - assert.Check(t, err) + assert.NilError(t, err) expected := &swarm.ResourceRequirements{ Limits: &swarm.Resources{ @@ -109,7 +109,7 @@ func TestConvertResourcesOnlyMemory(t *testing.T) { }, } resources, err := convertResources(source) - assert.Check(t, err) + assert.NilError(t, err) expected := &swarm.ResourceRequirements{ Limits: &swarm.Resources{ @@ -140,7 +140,7 @@ func TestConvertHealthcheck(t *testing.T) { } healthcheck, err := convertHealthcheck(source) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, healthcheck)) } @@ -151,7 +151,7 @@ func TestConvertHealthcheckDisable(t *testing.T) { } healthcheck, err := convertHealthcheck(source) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, healthcheck)) } @@ -195,7 +195,7 @@ func TestConvertEndpointSpec(t *testing.T) { }, } - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, *endpoint)) } @@ -212,7 +212,7 @@ func TestConvertServiceNetworksOnlyDefault(t *testing.T) { }, } - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, configs)) } @@ -250,7 +250,7 @@ func TestConvertServiceNetworks(t *testing.T) { sortedConfigs := byTargetSort(configs) sort.Sort(&sortedConfigs) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, []swarm.NetworkAttachmentConfig(sortedConfigs))) } @@ -273,7 +273,7 @@ func TestConvertServiceNetworksCustomDefault(t *testing.T) { }, } - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, []swarm.NetworkAttachmentConfig(configs))) } @@ -294,7 +294,7 @@ func (s byTargetSort) Swap(i, j int) { func TestConvertDNSConfigEmpty(t *testing.T) { dnsConfig, err := convertDNSConfig(nil, nil) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual((*swarm.DNSConfig)(nil), dnsConfig)) } @@ -305,7 +305,7 @@ var ( func TestConvertDNSConfigAll(t *testing.T) { dnsConfig, err := convertDNSConfig(nameservers, search) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(&swarm.DNSConfig{ Nameservers: nameservers, Search: search, @@ -314,7 +314,7 @@ func TestConvertDNSConfigAll(t *testing.T) { func TestConvertDNSConfigNameservers(t *testing.T) { dnsConfig, err := convertDNSConfig(nameservers, nil) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(&swarm.DNSConfig{ Nameservers: nameservers, Search: nil, @@ -323,7 +323,7 @@ func TestConvertDNSConfigNameservers(t *testing.T) { func TestConvertDNSConfigSearch(t *testing.T) { dnsConfig, err := convertDNSConfig(nil, search) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(&swarm.DNSConfig{ Nameservers: nil, Search: search, @@ -332,20 +332,20 @@ func TestConvertDNSConfigSearch(t *testing.T) { func TestConvertCredentialSpec(t *testing.T) { swarmSpec, err := convertCredentialSpec(composetypes.CredentialSpecConfig{}) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Nil(swarmSpec)) swarmSpec, err = convertCredentialSpec(composetypes.CredentialSpecConfig{ File: "/foo", }) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal(swarmSpec.File, "/foo")) assert.Check(t, is.Equal(swarmSpec.Registry, "")) swarmSpec, err = convertCredentialSpec(composetypes.CredentialSpecConfig{ Registry: "foo", }) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal(swarmSpec.File, "")) assert.Check(t, is.Equal(swarmSpec.Registry, "foo")) diff --git a/cli/compose/convert/volume_test.go b/cli/compose/convert/volume_test.go index 0cb3e72342..13e910fde5 100644 --- a/cli/compose/convert/volume_test.go +++ b/cli/compose/convert/volume_test.go @@ -19,7 +19,7 @@ func TestConvertVolumeToMountAnonymousVolume(t *testing.T) { Target: "/foo/bar", } mount, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo")) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, mount)) } @@ -174,7 +174,7 @@ func TestConvertVolumeToMountNamedVolume(t *testing.T) { }, } mount, err := convertVolumeToMount(config, stackVolumes, namespace) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, mount)) } @@ -221,7 +221,7 @@ func TestConvertVolumeToMountNamedVolumeWithNameCustomizd(t *testing.T) { }, } mount, err := convertVolumeToMount(config, stackVolumes, namespace) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, mount)) } @@ -245,7 +245,7 @@ func TestConvertVolumeToMountNamedVolumeExternal(t *testing.T) { Target: "/foo", } mount, err := convertVolumeToMount(config, stackVolumes, namespace) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, mount)) } @@ -274,7 +274,7 @@ func TestConvertVolumeToMountNamedVolumeExternalNoCopy(t *testing.T) { }, } mount, err := convertVolumeToMount(config, stackVolumes, namespace) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, mount)) } @@ -296,7 +296,7 @@ func TestConvertVolumeToMountBind(t *testing.T) { Bind: &composetypes.ServiceVolumeBind{Propagation: "shared"}, } mount, err := convertVolumeToMount(config, stackVolumes, namespace) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, mount)) } @@ -326,7 +326,7 @@ func TestConvertTmpfsToMountVolume(t *testing.T) { TmpfsOptions: &mount.TmpfsOptions{SizeBytes: 1000}, } mount, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo")) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, mount)) } diff --git a/cli/compose/interpolation/interpolation_test.go b/cli/compose/interpolation/interpolation_test.go index 63e078c1d5..ca3d5f4993 100644 --- a/cli/compose/interpolation/interpolation_test.go +++ b/cli/compose/interpolation/interpolation_test.go @@ -47,7 +47,7 @@ func TestInterpolate(t *testing.T) { }, } result, err := Interpolate(services, Options{LookupValue: defaultMapping}) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, result)) } @@ -75,7 +75,7 @@ func TestInterpolateWithDefaults(t *testing.T) { }, } result, err := Interpolate(config, Options{}) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, result)) } @@ -92,7 +92,7 @@ func TestInterpolateWithCast(t *testing.T) { LookupValue: defaultMapping, TypeCastMapping: map[Path]Cast{NewPath(PathMatchAll, "replicas"): toInt}, }) - assert.Check(t, err) + assert.NilError(t, err) expected := map[string]interface{}{ "foo": map[string]interface{}{ "replicas": 5, diff --git a/cli/compose/loader/loader_test.go b/cli/compose/loader/loader_test.go index 93f87cefa8..4219593725 100644 --- a/cli/compose/loader/loader_test.go +++ b/cli/compose/loader/loader_test.go @@ -410,7 +410,7 @@ services: - QUX= - QUUX `, map[string]string{"QUX": "qux"}) - assert.Check(t, err) + assert.NilError(t, err) expected := types.MappingWithEquals{ "FOO": strPtr("1"), diff --git a/cli/compose/loader/types_test.go b/cli/compose/loader/types_test.go index 7ada6a1ab0..b324c8e580 100644 --- a/cli/compose/loader/types_test.go +++ b/cli/compose/loader/types_test.go @@ -319,12 +319,12 @@ configs: {} ` actual, err := yaml.Marshal(cfg) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal(expected, string(actual))) // Make sure the expected still dict, err := ParseYAML([]byte("version: '3.6'\n" + expected)) - assert.Check(t, err) + assert.NilError(t, err) _, err = Load(buildConfigDetails(dict, map[string]string{})) - assert.Check(t, err) + assert.NilError(t, err) } diff --git a/cli/compose/loader/volume_test.go b/cli/compose/loader/volume_test.go index 8eb4c6d991..636696af8a 100644 --- a/cli/compose/loader/volume_test.go +++ b/cli/compose/loader/volume_test.go @@ -13,7 +13,7 @@ func TestParseVolumeAnonymousVolume(t *testing.T) { for _, path := range []string{"/path", "/path/foo"} { volume, err := ParseVolume(path) expected := types.ServiceVolumeConfig{Type: "volume", Target: path} - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, volume)) } } @@ -22,7 +22,7 @@ func TestParseVolumeAnonymousVolumeWindows(t *testing.T) { for _, path := range []string{"C:\\path", "Z:\\path\\foo"} { volume, err := ParseVolume(path) expected := types.ServiceVolumeConfig{Type: "volume", Target: path} - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, volume)) } } @@ -36,7 +36,7 @@ func TestParseVolumeShortVolumes(t *testing.T) { for _, path := range []string{".", "/a"} { volume, err := ParseVolume(path) expected := types.ServiceVolumeConfig{Type: "volume", Target: path} - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, volume)) } } @@ -56,7 +56,7 @@ func TestParseVolumeBindMount(t *testing.T) { Source: path, Target: "/target", } - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, volume)) } } @@ -74,7 +74,7 @@ func TestParseVolumeRelativeBindMountWindows(t *testing.T) { Source: path, Target: "d:\\target", } - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, volume)) } } @@ -87,7 +87,7 @@ func TestParseVolumeWithBindOptions(t *testing.T) { Target: "/target", Bind: &types.ServiceVolumeBind{Propagation: "slave"}, } - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, volume)) } @@ -100,13 +100,13 @@ func TestParseVolumeWithBindOptionsWindows(t *testing.T) { ReadOnly: true, Bind: &types.ServiceVolumeBind{Propagation: "rprivate"}, } - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, volume)) } func TestParseVolumeWithInvalidVolumeOptions(t *testing.T) { _, err := ParseVolume("name:/target:bogus") - assert.Check(t, err) + assert.NilError(t, err) } func TestParseVolumeWithVolumeOptions(t *testing.T) { @@ -117,7 +117,7 @@ func TestParseVolumeWithVolumeOptions(t *testing.T) { Target: "/target", Volume: &types.ServiceVolumeVolume{NoCopy: true}, } - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, volume)) } @@ -130,7 +130,7 @@ func TestParseVolumeWithReadOnly(t *testing.T) { Target: "/target", ReadOnly: true, } - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, volume)) } } @@ -144,7 +144,7 @@ func TestParseVolumeWithRW(t *testing.T) { Target: "/target", ReadOnly: false, } - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, volume)) } } diff --git a/cli/compose/schema/schema_test.go b/cli/compose/schema/schema_test.go index 7dd9d296a9..ad1af2d5b8 100644 --- a/cli/compose/schema/schema_test.go +++ b/cli/compose/schema/schema_test.go @@ -42,7 +42,7 @@ func TestValidateAllowsXTopLevelFields(t *testing.T) { } err := Validate(config, "3.4") - assert.Check(t, err) + assert.NilError(t, err) } func TestValidateSecretConfigNames(t *testing.T) { @@ -61,7 +61,7 @@ func TestValidateSecretConfigNames(t *testing.T) { } err := Validate(config, "3.5") - assert.Check(t, err) + assert.NilError(t, err) } func TestValidateInvalidVersion(t *testing.T) { diff --git a/cli/compose/template/template_test.go b/cli/compose/template/template_test.go index 7adef7b13a..5e4ff9b3ed 100644 --- a/cli/compose/template/template_test.go +++ b/cli/compose/template/template_test.go @@ -20,7 +20,7 @@ func defaultMapping(name string) (string, bool) { func TestEscaped(t *testing.T) { result, err := Substitute("$${foo}", defaultMapping) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal("${foo}", result)) } @@ -50,7 +50,7 @@ func TestInvalid(t *testing.T) { func TestNoValueNoDefault(t *testing.T) { for _, template := range []string{"This ${missing} var", "This ${BAR} var"} { result, err := Substitute(template, defaultMapping) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal("This var", result)) } } @@ -58,7 +58,7 @@ func TestNoValueNoDefault(t *testing.T) { func TestValueNoDefault(t *testing.T) { for _, template := range []string{"This $FOO var", "This ${FOO} var"} { result, err := Substitute(template, defaultMapping) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal("This first var", result)) } } @@ -66,26 +66,26 @@ func TestValueNoDefault(t *testing.T) { func TestNoValueWithDefault(t *testing.T) { for _, template := range []string{"ok ${missing:-def}", "ok ${missing-def}"} { result, err := Substitute(template, defaultMapping) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal("ok def", result)) } } func TestEmptyValueWithSoftDefault(t *testing.T) { result, err := Substitute("ok ${BAR:-def}", defaultMapping) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal("ok def", result)) } func TestEmptyValueWithHardDefault(t *testing.T) { result, err := Substitute("ok ${BAR-def}", defaultMapping) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal("ok ", result)) } func TestNonAlphanumericDefault(t *testing.T) { result, err := Substitute("ok ${BAR:-/non:-alphanumeric}", defaultMapping) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal("ok /non:-alphanumeric", result)) } @@ -144,7 +144,7 @@ func TestDefaultsForMandatoryVariables(t *testing.T) { for _, tc := range testCases { result, err := Substitute(tc.template, defaultMapping) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal(tc.expected, result)) } } diff --git a/cli/config/credentials/native_store_test.go b/cli/config/credentials/native_store_test.go index c73ddd1ea3..57a506f62c 100644 --- a/cli/config/credentials/native_store_test.go +++ b/cli/config/credentials/native_store_test.go @@ -227,7 +227,7 @@ func TestNativeStoreGetMissingCredentials(t *testing.T) { fileStore: NewFileStore(f), } _, err := s.Get(missingCredsAddress) - assert.Check(t, err) + assert.NilError(t, err) } func TestNativeStoreGetInvalidAddress(t *testing.T) { diff --git a/cli/flags/common_test.go b/cli/flags/common_test.go index 1482c33f6c..2f06e11e44 100644 --- a/cli/flags/common_test.go +++ b/cli/flags/common_test.go @@ -20,7 +20,7 @@ func TestCommonOptionsInstallFlags(t *testing.T) { "--tlscert=\"/foo/cert\"", "--tlskey=\"/foo/key\"", }) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal("/foo/cafile", opts.TLSOptions.CAFile)) assert.Check(t, is.Equal("/foo/cert", opts.TLSOptions.CertFile)) assert.Check(t, is.Equal(opts.TLSOptions.KeyFile, "/foo/key")) @@ -36,7 +36,7 @@ func TestCommonOptionsInstallFlagsWithDefaults(t *testing.T) { opts.InstallFlags(flags) err := flags.Parse([]string{}) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal(defaultPath("ca.pem"), opts.TLSOptions.CAFile)) assert.Check(t, is.Equal(defaultPath("cert.pem"), opts.TLSOptions.CertFile)) assert.Check(t, is.Equal(defaultPath("key.pem"), opts.TLSOptions.KeyFile)) diff --git a/cli/trust/trust_test.go b/cli/trust/trust_test.go index 0cb1f1dd26..9cb7f48af6 100644 --- a/cli/trust/trust_test.go +++ b/cli/trust/trust_test.go @@ -16,41 +16,41 @@ import ( func TestGetTag(t *testing.T) { ref, err := reference.ParseNormalizedNamed("ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2") - assert.Check(t, err) + assert.NilError(t, err) tag := getTag(ref) assert.Check(t, is.Equal("", tag)) ref, err = reference.ParseNormalizedNamed("alpine:latest") - assert.Check(t, err) + assert.NilError(t, err) tag = getTag(ref) assert.Check(t, is.Equal(tag, "latest")) ref, err = reference.ParseNormalizedNamed("alpine") - assert.Check(t, err) + assert.NilError(t, err) tag = getTag(ref) assert.Check(t, is.Equal(tag, "")) } func TestGetDigest(t *testing.T) { ref, err := reference.ParseNormalizedNamed("ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2") - assert.Check(t, err) + assert.NilError(t, err) d := getDigest(ref) assert.Check(t, is.Equal(digest.Digest("sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2"), d)) ref, err = reference.ParseNormalizedNamed("alpine:latest") - assert.Check(t, err) + assert.NilError(t, err) d = getDigest(ref) assert.Check(t, is.Equal(digest.Digest(""), d)) ref, err = reference.ParseNormalizedNamed("alpine") - assert.Check(t, err) + assert.NilError(t, err) d = getDigest(ref) assert.Check(t, is.Equal(digest.Digest(""), d)) } func TestGetSignableRolesError(t *testing.T) { tmpDir, err := ioutil.TempDir("", "notary-test-") - assert.Check(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{}) diff --git a/cmd/docker/docker_test.go b/cmd/docker/docker_test.go index 4165388b80..c0613bb1ae 100644 --- a/cmd/docker/docker_test.go +++ b/cmd/docker/docker_test.go @@ -19,7 +19,7 @@ func TestClientDebugEnabled(t *testing.T) { cmd.Flags().Set("debug", "true") err := cmd.PersistentPreRunE(cmd, []string{}) - assert.Check(t, err) + assert.NilError(t, err) assert.Check(t, is.Equal("1", os.Getenv("DEBUG"))) assert.Check(t, is.Equal(logrus.DebugLevel, logrus.GetLevel())) } diff --git a/templates/templates_test.go b/templates/templates_test.go index 66fafa2f07..e2f5df642f 100644 --- a/templates/templates_test.go +++ b/templates/templates_test.go @@ -11,7 +11,7 @@ import ( // GitHub #32120 func TestParseJSONFunctions(t *testing.T) { tm, err := Parse(`{{json .Ports}}`) - assert.Check(t, err) + 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"})) @@ -21,7 +21,7 @@ func TestParseJSONFunctions(t *testing.T) { func TestParseStringFunctions(t *testing.T) { tm, err := Parse(`{{join (split . ":") "/"}}`) - assert.Check(t, err) + assert.NilError(t, err) var b bytes.Buffer assert.Check(t, tm.Execute(&b, "text:with:colon")) @@ -31,7 +31,7 @@ func TestParseStringFunctions(t *testing.T) { func TestNewParse(t *testing.T) { tm, err := NewParse("foo", "this is a {{ . }}") - assert.Check(t, err) + assert.NilError(t, err) var b bytes.Buffer assert.Check(t, tm.Execute(&b, "string")) @@ -66,7 +66,7 @@ func TestParseTruncateFunction(t *testing.T) { for _, testCase := range testCases { tm, err := Parse(testCase.template) - assert.Check(t, err) + assert.NilError(t, err) t.Run("Non Empty Source Test with template: "+testCase.template, func(t *testing.T) { var b bytes.Buffer