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 <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2018-03-06 14:44:13 -05:00
parent 0f11a310fd
commit baf65a5502
46 changed files with 173 additions and 173 deletions

View File

@ -26,7 +26,7 @@ func TestLoadFileV01Success(t *testing.T) {
}`) }`)
bundle, err := LoadFile(reader) 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.Equal("0.1", bundle.Version))
assert.Check(t, is.Len(bundle.Services, 2)) assert.Check(t, is.Len(bundle.Services, 2))
} }

View File

@ -163,7 +163,7 @@ func TestExperimentalCLI(t *testing.T) {
cli := &DockerCli{client: apiclient, err: os.Stderr} cli := &DockerCli{client: apiclient, err: os.Stderr}
cliconfig.SetDir(dir.Path()) cliconfig.SetDir(dir.Path())
err := cli.Initialize(flags.NewClientOptions()) err := cli.Initialize(flags.NewClientOptions())
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(testcase.expectedExperimentalCLI, cli.ClientInfo().HasExperimental)) assert.Check(t, is.Equal(testcase.expectedExperimentalCLI, cli.ClientInfo().HasExperimental))
}) })
} }
@ -266,7 +266,7 @@ func TestOrchestratorSwitch(t *testing.T) {
options.Common.Orchestrator = testcase.flagOrchestrator options.Common.Orchestrator = testcase.flagOrchestrator
} }
err := cli.Initialize(options) 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.expectedKubernetes, cli.ClientInfo().HasKubernetes()))
assert.Check(t, is.Equal(testcase.expectedOrchestrator, string(cli.ClientInfo().Orchestrator))) assert.Check(t, is.Equal(testcase.expectedOrchestrator, string(cli.ClientInfo().Orchestrator)))
}) })
@ -334,7 +334,7 @@ func TestGetClientWithPassword(t *testing.T) {
return return
} }
assert.Check(t, err) assert.NilError(t, err)
}) })
} }
} }

View File

@ -83,7 +83,7 @@ func TestConfigCreateWithLabels(t *testing.T) {
name := "foo" name := "foo"
data, err := ioutil.ReadFile(filepath.Join("testdata", configDataFile)) data, err := ioutil.ReadFile(filepath.Join("testdata", configDataFile))
assert.Check(t, err) assert.NilError(t, err)
expected := swarm.ConfigSpec{ expected := swarm.ConfigSpec{
Annotations: swarm.Annotations{ Annotations: swarm.Annotations{

View File

@ -122,7 +122,7 @@ func TestGetExitStatus(t *testing.T) {
} }
err := getExitStatus(errC, resultC) err := getExitStatus(errC, resultC)
if testcase.expectedError == nil { if testcase.expectedError == nil {
assert.Check(t, err) assert.NilError(t, err)
} else { } else {
assert.Check(t, is.Error(err, testcase.expectedError.Error())) assert.Check(t, is.Error(err, testcase.expectedError.Error()))
} }

View File

@ -71,7 +71,7 @@ func parseMustError(t *testing.T, args string) {
func mustParse(t *testing.T, args string) (*container.Config, *container.HostConfig) { func mustParse(t *testing.T, args string) (*container.Config, *container.HostConfig) {
config, hostConfig, _, err := parseRun(append(strings.Split(args, " "), "ubuntu", "bash")) config, hostConfig, _, err := parseRun(append(strings.Split(args, " "), "ubuntu", "bash"))
assert.Check(t, err) assert.NilError(t, err)
return config, hostConfig return config, hostConfig
} }

View File

@ -102,7 +102,7 @@ func TestBuildContainerListOptions(t *testing.T) {
for _, c := range contexts { for _, c := range contexts {
options, err := buildContainerListOptions(c.psOpts) 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.expectedAll, options.All))
assert.Check(t, is.Equal(c.expectedSize, options.Size)) assert.Check(t, is.Equal(c.expectedSize, options.Size))

View File

@ -153,7 +153,7 @@ func TestTrustTagContextEmptyWrite(t *testing.T) {
out := bytes.NewBufferString("") out := bytes.NewBufferString("")
emptyCase.context.Output = out emptyCase.context.Output = out
err := TrustTagWrite(emptyCase.context, emptySignedTags) err := TrustTagWrite(emptyCase.context, emptySignedTags)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(emptyCase.expected, out.String())) assert.Check(t, is.Equal(emptyCase.expected, out.String()))
} }
@ -172,7 +172,7 @@ func TestSignerInfoContextEmptyWrite(t *testing.T) {
out := bytes.NewBufferString("") out := bytes.NewBufferString("")
emptyCase.context.Output = out emptyCase.context.Output = out
err := SignerInfoWrite(emptyCase.context, emptySignerInfo) err := SignerInfoWrite(emptyCase.context, emptySignerInfo)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(emptyCase.expected, out.String())) assert.Check(t, is.Equal(emptyCase.expected, out.String()))
} }

View File

@ -41,7 +41,7 @@ func TestResolveWithNoResolveOption(t *testing.T) {
idResolver := New(cli, true) idResolver := New(cli, true)
id, err := idResolver.Resolve(context.Background(), swarm.Node{}, "nodeID") 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, is.Equal("nodeID", id))
assert.Check(t, !resolved) assert.Check(t, !resolved)
} }
@ -60,7 +60,7 @@ func TestResolveWithCache(t *testing.T) {
ctx := context.Background() ctx := context.Background()
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
id, err := idResolver.Resolve(ctx, swarm.Node{}, "nodeID") id, err := idResolver.Resolve(ctx, swarm.Node{}, "nodeID")
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal("node-foo", id)) assert.Check(t, is.Equal("node-foo", id))
} }
@ -104,7 +104,7 @@ func TestResolveNode(t *testing.T) {
idResolver := New(cli, false) idResolver := New(cli, false)
id, err := idResolver.Resolve(ctx, swarm.Node{}, tc.nodeID) 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)) assert.Check(t, is.Equal(tc.expectedID, id))
} }
} }
@ -139,7 +139,7 @@ func TestResolveService(t *testing.T) {
idResolver := New(cli, false) idResolver := New(cli, false)
id, err := idResolver.Resolve(ctx, swarm.Service{}, tc.serviceID) 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)) assert.Check(t, is.Equal(tc.expectedID, id))
} }
} }

View File

@ -91,7 +91,7 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
err := cmd.Execute() err := cmd.Execute()
assert.Check(t, err) assert.NilError(t, err)
actual := cli.OutBuffer().String() actual := cli.OutBuffer().String()
golden.Assert(t, actual, fmt.Sprintf("history-command-success.%s.golden", tc.name)) golden.Assert(t, actual, fmt.Sprintf("history-command-success.%s.golden", tc.name))
} }

View File

@ -81,7 +81,7 @@ func TestNewInspectCommandSuccess(t *testing.T) {
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
err := cmd.Execute() 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)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("inspect-command-success.%s.golden", tc.name))
assert.Check(t, is.Equal(imageInspectInvocationCount, tc.imageCount)) assert.Check(t, is.Equal(imageInspectInvocationCount, tc.imageCount))
} }

View File

@ -85,7 +85,7 @@ func TestNewImagesCommandSuccess(t *testing.T) {
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
err := cmd.Execute() 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)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("list-command-success.%s.golden", tc.name))
} }
} }

View File

@ -95,7 +95,7 @@ func TestNewLoadCommandSuccess(t *testing.T) {
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
err := cmd.Execute() 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)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("load-command-success.%s.golden", tc.name))
} }
} }

View File

@ -88,7 +88,7 @@ func TestNewPruneCommandSuccess(t *testing.T) {
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
err := cmd.Execute() 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)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("prune-command-success.%s.golden", tc.name))
} }
} }

View File

@ -73,7 +73,7 @@ func TestNewPullCommandSuccess(t *testing.T) {
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
err := cmd.Execute() 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)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("pull-command-success.%s.golden", tc.name))
} }
} }

View File

@ -64,7 +64,7 @@ func TestNonOfficialTrustServer(t *testing.T) {
func TestAddTargetToAllSignableRolesError(t *testing.T) { func TestAddTargetToAllSignableRolesError(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "notary-test-") tmpDir, err := ioutil.TempDir("", "notary-test-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{}) notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{})

View File

@ -140,7 +140,7 @@ func TestGetDefaultAuthConfig(t *testing.T) {
assert.Check(t, err != nil) assert.Check(t, err != nil)
assert.Check(t, is.Equal(tc.expectedErr, err.Error())) assert.Check(t, is.Equal(tc.expectedErr, err.Error()))
} else { } else {
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(tc.expectedAuthConfig, *authconfig)) assert.Check(t, is.DeepEqual(tc.expectedAuthConfig, *authconfig))
} }
} }

View File

@ -52,7 +52,7 @@ func TestSecretCreateErrors(t *testing.T) {
func TestSecretCreateWithName(t *testing.T) { func TestSecretCreateWithName(t *testing.T) {
name := "foo" name := "foo"
data, err := ioutil.ReadFile(filepath.Join("testdata", secretDataFile)) data, err := ioutil.ReadFile(filepath.Join("testdata", secretDataFile))
assert.Check(t, err) assert.NilError(t, err)
expected := swarm.SecretSpec{ expected := swarm.SecretSpec{
Annotations: swarm.Annotations{ Annotations: swarm.Annotations{

View File

@ -18,6 +18,6 @@ func TestValidateSingleGenericResource(t *testing.T) {
for _, v := range correct { for _, v := range correct {
_, err := ValidateSingleGenericResource(v) _, err := ValidateSingleGenericResource(v)
assert.Check(t, err) assert.NilError(t, err)
} }
} }

View File

@ -61,7 +61,7 @@ func TestHealthCheckOptionsToHealthConfig(t *testing.T) {
retries: 10, retries: 10,
} }
config, err := opt.toHealthConfig() config, err := opt.toHealthConfig()
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(&container.HealthConfig{ assert.Check(t, is.DeepEqual(&container.HealthConfig{
Test: []string{"CMD-SHELL", "curl"}, Test: []string{"CMD-SHELL", "curl"},
Interval: time.Second, Interval: time.Second,
@ -76,7 +76,7 @@ func TestHealthCheckOptionsToHealthConfigNoHealthcheck(t *testing.T) {
noHealthcheck: true, noHealthcheck: true,
} }
config, err := opt.toHealthConfig() config, err := opt.toHealthConfig()
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(&container.HealthConfig{ assert.Check(t, is.DeepEqual(&container.HealthConfig{
Test: []string{"NONE"}, Test: []string{"NONE"},
}, config)) }, config))
@ -123,7 +123,7 @@ func TestResourceOptionsToResourceRequirements(t *testing.T) {
for _, opt := range correctOptions { for _, opt := range correctOptions {
r, err := opt.ToResourceRequirements() r, err := opt.ToResourceRequirements()
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Len(r.Reservations.GenericResources, len(opt.resGenericResources))) assert.Check(t, is.Len(r.Reservations.GenericResources, len(opt.resGenericResources)))
} }

View File

@ -244,7 +244,7 @@ func TestUpdatePorts(t *testing.T) {
} }
err := updatePorts(flags, &portConfigs) err := updatePorts(flags, &portConfigs)
assert.Check(t, err) assert.NilError(t, err)
assert.Assert(t, is.Len(portConfigs, 2)) assert.Assert(t, is.Len(portConfigs, 2))
// Do a sort to have the order (might have changed by map) // Do a sort to have the order (might have changed by map)
targetPorts := []int{int(portConfigs[0].TargetPort), int(portConfigs[1].TargetPort)} targetPorts := []int{int(portConfigs[0].TargetPort), int(portConfigs[1].TargetPort)}
@ -268,7 +268,7 @@ func TestUpdatePortsDuplicate(t *testing.T) {
} }
err := updatePorts(flags, &portConfigs) err := updatePorts(flags, &portConfigs)
assert.Check(t, err) assert.NilError(t, err)
assert.Assert(t, is.Len(portConfigs, 1)) assert.Assert(t, is.Len(portConfigs, 1))
assert.Check(t, is.Equal(uint32(80), portConfigs[0].TargetPort)) assert.Check(t, is.Equal(uint32(80), portConfigs[0].TargetPort))
} }
@ -346,7 +346,7 @@ func TestUpdateHealthcheckTable(t *testing.T) {
if c.err != "" { if c.err != "" {
assert.Check(t, is.Error(err, c.err)) assert.Check(t, is.Error(err, c.err))
} else { } else {
assert.Check(t, err) assert.NilError(t, err)
if !reflect.DeepEqual(cspec.Healthcheck, c.expected) { 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) 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"} expected := []string{"1.2.3.4 example.com", "4.3.2.1 example.org", "2001:db8:abc8::1 ipv6.net"}
err := updateHosts(flags, &hosts) err := updateHosts(flags, &hosts)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, hosts)) assert.Check(t, is.DeepEqual(expected, hosts))
} }
@ -381,7 +381,7 @@ func TestUpdateHostsPreservesOrder(t *testing.T) {
hosts := []string{} hosts := []string{}
err := updateHosts(flags, &hosts) 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)) 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) err := updatePorts(flags, &portConfigs)
assert.Check(t, err) assert.NilError(t, err)
assert.Assert(t, is.Len(portConfigs, 2)) assert.Assert(t, is.Len(portConfigs, 2))
assert.Check(t, is.Equal(uint32(81), portConfigs[0].TargetPort)) assert.Check(t, is.Equal(uint32(81), portConfigs[0].TargetPort))
assert.Check(t, is.Equal(uint32(82), portConfigs[1].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) updatedSecrets, err := getUpdatedSecrets(apiClient, flags, secrets)
assert.Check(t, err) assert.NilError(t, err)
assert.Assert(t, is.Len(updatedSecrets, 1)) assert.Assert(t, is.Len(updatedSecrets, 1))
assert.Check(t, is.Equal("tn9qiblgnuuut11eufquw5dev", updatedSecrets[0].SecretID)) assert.Check(t, is.Equal("tn9qiblgnuuut11eufquw5dev", updatedSecrets[0].SecretID))
assert.Check(t, is.Equal("foo", updatedSecrets[0].SecretName)) assert.Check(t, is.Equal("foo", updatedSecrets[0].SecretName))
@ -640,7 +640,7 @@ func TestUpdateNetworks(t *testing.T) {
err = flags.Set(flagNetworkRemove, "id999") err = flags.Set(flagNetworkRemove, "id999")
assert.NilError(t, err) assert.NilError(t, err)
err = updateService(ctx, client, flags, &svc) 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)) assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id555"}}, svc.TaskTemplate.Networks))
flags = newUpdateCommand(nil).Flags() flags = newUpdateCommand(nil).Flags()
@ -649,6 +649,6 @@ func TestUpdateNetworks(t *testing.T) {
err = flags.Set(flagNetworkRemove, "aaa-network") err = flags.Set(flagNetworkRemove, "aaa-network")
assert.NilError(t, err) assert.NilError(t, err)
err = updateService(ctx, client, flags, &svc) 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)) assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id999"}}, svc.TaskTemplate.Networks))
} }

View File

@ -45,6 +45,6 @@ func TestLoadBundlefile(t *testing.T) {
path := filepath.Join("testdata", "bundlefile_with_two_services.dab") path := filepath.Join("testdata", "bundlefile_with_two_services.dab")
bundleFile, err := loadBundlefile(buf, namespace, path) bundleFile, err := loadBundlefile(buf, namespace, path)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(len(bundleFile.Services), 2)) assert.Check(t, is.Equal(len(bundleFile.Services), 2))
} }

View File

@ -56,7 +56,7 @@ func TestValidateExternalNetworks(t *testing.T) {
networks := []string{testcase.network} networks := []string{testcase.network}
err := validateExternalNetworks(context.Background(), fakeClient, networks) err := validateExternalNetworks(context.Background(), fakeClient, networks)
if testcase.expectedMsg == "" { if testcase.expectedMsg == "" {
assert.Check(t, err) assert.NilError(t, err)
} else { } else {
assert.ErrorContains(t, err, testcase.expectedMsg) assert.ErrorContains(t, err, testcase.expectedMsg)
} }

View File

@ -94,7 +94,7 @@ func TestServiceUpdateResolveImageChanged(t *testing.T) {
}, },
} }
err := deployServices(ctx, client, spec, namespace, false, ResolveImageChanged) 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.expectedQueryRegistry, receivedOptions.QueryRegistry))
assert.Check(t, is.Equal(testcase.expectedImage, receivedService.TaskTemplate.ContainerSpec.Image)) assert.Check(t, is.Equal(testcase.expectedImage, receivedService.TaskTemplate.ContainerSpec.Image))

View File

@ -40,7 +40,7 @@ func TestDisplayTrustRootNoRoot(t *testing.T) {
func TestDisplayTrustRootInvalidFlags(t *testing.T) { func TestDisplayTrustRootInvalidFlags(t *testing.T) {
// we need an actual PEMfile to test // we need an actual PEMfile to test
tmpfile, err := ioutil.TempFile("", "pemfile") tmpfile, err := ioutil.TempFile("", "pemfile")
assert.Check(t, err) assert.NilError(t, err)
defer os.Remove(tmpfile.Name()) defer os.Remove(tmpfile.Name())
tmpfile.Write([]byte(` tmpfile.Write([]byte(`
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----

View File

@ -24,7 +24,7 @@ func TestTaskPrintWithQuietOption(t *testing.T) {
cli := test.NewFakeCli(apiClient) cli := test.NewFakeCli(apiClient)
tasks := []swarm.Task{*Task(TaskID("id-foo"))} tasks := []swarm.Task{*Task(TaskID("id-foo"))}
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, formatter.TableFormatKey) 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") 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")), *Task(TaskID("id-foo-yov6omdek8fg3k5stosyp2m50")),
} }
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .ID }}") 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") 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)), *Task(TaskServiceID("service-id-foo"), TaskNodeID("node-id-bar"), TaskSlot(0)),
} }
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .Name }}") 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") 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)), *Task(TaskServiceID("service-id-foo"), TaskSlot(1)),
} }
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .Name }}") 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") 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) 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") 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)), *Task(TaskServiceID("service-id-foo"), TaskSlot(1)),
} }
err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .Name }} {{ .Node }}") 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") golden.Assert(t, cli.OutBuffer().String(), "task-print-with-resolution.golden")
} }

View File

@ -14,11 +14,11 @@ import (
func TestGetOrGenerateNotaryKeyAndInitRepo(t *testing.T) { func TestGetOrGenerateNotaryKeyAndInitRepo(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "notary-test-") tmpDir, err := ioutil.TempDir("", "notary-test-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{}) 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) err = getOrGenerateRootKeyAndInitRepo(notaryRepo)
assert.Check(t, is.Error(err, "client is offline")) assert.Check(t, is.Error(err, "client is offline"))

View File

@ -36,7 +36,7 @@ func TestTrustKeyGenerateErrors(t *testing.T) {
} }
tmpDir, err := ioutil.TempDir("", "docker-key-generate-test-") tmpDir, err := ioutil.TempDir("", "docker-key-generate-test-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
config.SetDir(tmpDir) config.SetDir(tmpDir)
@ -51,11 +51,11 @@ func TestTrustKeyGenerateErrors(t *testing.T) {
func TestGenerateKeySuccess(t *testing.T) { func TestGenerateKeySuccess(t *testing.T) {
pubKeyCWD, err := ioutil.TempDir("", "pub-keys-") pubKeyCWD, err := ioutil.TempDir("", "pub-keys-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(pubKeyCWD) defer os.RemoveAll(pubKeyCWD)
privKeyStorageDir, err := ioutil.TempDir("", "priv-keys-") privKeyStorageDir, err := ioutil.TempDir("", "priv-keys-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(privKeyStorageDir) defer os.RemoveAll(privKeyStorageDir)
passwd := "password" passwd := "password"
@ -63,10 +63,10 @@ func TestGenerateKeySuccess(t *testing.T) {
// generate a single key // generate a single key
keyName := "alice" keyName := "alice"
privKeyFileStore, err := trustmanager.NewKeyFileStore(privKeyStorageDir, cannedPasswordRetriever) privKeyFileStore, err := trustmanager.NewKeyFileStore(privKeyStorageDir, cannedPasswordRetriever)
assert.Check(t, err) assert.NilError(t, err)
pubKeyPEM, err := generateKeyAndOutputPubPEM(keyName, privKeyFileStore) pubKeyPEM, err := generateKeyAndOutputPubPEM(keyName, privKeyFileStore)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(keyName, pubKeyPEM.Headers["role"])) assert.Check(t, is.Equal(keyName, pubKeyPEM.Headers["role"]))
// the default GUN is empty // the default GUN is empty
@ -77,10 +77,10 @@ func TestGenerateKeySuccess(t *testing.T) {
// check that an appropriate ~/<trust_dir>/private/<key_id>.key file exists // check that an appropriate ~/<trust_dir>/private/<key_id>.key file exists
expectedPrivKeyDir := filepath.Join(privKeyStorageDir, notary.PrivDir) expectedPrivKeyDir := filepath.Join(privKeyStorageDir, notary.PrivDir)
_, err = os.Stat(expectedPrivKeyDir) _, err = os.Stat(expectedPrivKeyDir)
assert.Check(t, err) assert.NilError(t, err)
keyFiles, err := ioutil.ReadDir(expectedPrivKeyDir) keyFiles, err := ioutil.ReadDir(expectedPrivKeyDir)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Len(keyFiles, 1)) assert.Check(t, is.Len(keyFiles, 1))
privKeyFilePath := filepath.Join(expectedPrivKeyDir, keyFiles[0].Name()) 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)) assert.Check(t, is.Equal("ENCRYPTED PRIVATE KEY", privKeyPEM.Type))
// check that the passphrase matches // check that the passphrase matches
_, err = tufutils.ParsePKCS8ToTufKey(privKeyPEM.Bytes, []byte(passwd)) _, 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: // check that the public key exists at the correct path if we use the helper:
returnedPath, err := writePubKeyPEMToDir(pubKeyPEM, keyName, pubKeyCWD) returnedPath, err := writePubKeyPEMToDir(pubKeyPEM, keyName, pubKeyCWD)
assert.Check(t, err) assert.NilError(t, err)
expectedPubKeyPath := filepath.Join(pubKeyCWD, keyName+".pub") expectedPubKeyPath := filepath.Join(pubKeyCWD, keyName+".pub")
assert.Check(t, is.Equal(returnedPath, expectedPubKeyPath)) assert.Check(t, is.Equal(returnedPath, expectedPubKeyPath))
_, err = os.Stat(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 // check that the public key is the only file output in CWD
cwdKeyFiles, err := ioutil.ReadDir(pubKeyCWD) cwdKeyFiles, err := ioutil.ReadDir(pubKeyCWD)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Len(cwdKeyFiles, 1)) assert.Check(t, is.Len(cwdKeyFiles, 1))
} }
func TestValidateKeyArgs(t *testing.T) { func TestValidateKeyArgs(t *testing.T) {
pubKeyCWD, err := ioutil.TempDir("", "pub-keys-") pubKeyCWD, err := ioutil.TempDir("", "pub-keys-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(pubKeyCWD) defer os.RemoveAll(pubKeyCWD)
err = validateKeyArgs("a", pubKeyCWD) err = validateKeyArgs("a", pubKeyCWD)
assert.Check(t, err) assert.NilError(t, err)
err = validateKeyArgs("a/b", pubKeyCWD) 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") assert.Error(t, err, "key name \"a/b\" must start with lowercase alphanumeric characters and can include \"-\" or \"_\" after the first character")

View File

@ -51,7 +51,7 @@ func TestTrustKeyLoadErrors(t *testing.T) {
}, },
} }
tmpDir, err := ioutil.TempDir("", "docker-key-load-test-") tmpDir, err := ioutil.TempDir("", "docker-key-load-test-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
config.SetDir(tmpDir) config.SetDir(tmpDir)
@ -118,24 +118,24 @@ func TestLoadKeyFromPath(t *testing.T) {
func testLoadKeyFromPath(t *testing.T, privKeyID string, privKeyFixture []byte) { func testLoadKeyFromPath(t *testing.T, privKeyID string, privKeyFixture []byte) {
privKeyDir, err := ioutil.TempDir("", "key-load-test-") privKeyDir, err := ioutil.TempDir("", "key-load-test-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(privKeyDir) defer os.RemoveAll(privKeyDir)
privKeyFilepath := filepath.Join(privKeyDir, "privkey.pem") privKeyFilepath := filepath.Join(privKeyDir, "privkey.pem")
assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, notary.PrivNoExecPerms)) assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, notary.PrivNoExecPerms))
keyStorageDir, err := ioutil.TempDir("", "loaded-keys-") keyStorageDir, err := ioutil.TempDir("", "loaded-keys-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(keyStorageDir) defer os.RemoveAll(keyStorageDir)
passwd := "password" passwd := "password"
cannedPasswordRetriever := passphrase.ConstantRetriever(passwd) cannedPasswordRetriever := passphrase.ConstantRetriever(passwd)
keyFileStore, err := storage.NewPrivateKeyFileStorage(keyStorageDir, notary.KeyExtension) keyFileStore, err := storage.NewPrivateKeyFileStorage(keyStorageDir, notary.KeyExtension)
assert.Check(t, err) assert.NilError(t, err)
privKeyImporters := []trustmanager.Importer{keyFileStore} privKeyImporters := []trustmanager.Importer{keyFileStore}
// get the privKeyBytes // get the privKeyBytes
privKeyBytes, err := getPrivKeyBytesFromPath(privKeyFilepath) privKeyBytes, err := getPrivKeyBytesFromPath(privKeyFilepath)
assert.Check(t, err) assert.NilError(t, err)
// import the key to our keyStorageDir // import the key to our keyStorageDir
assert.Check(t, loadPrivKeyBytesToStore(privKeyBytes, privKeyImporters, privKeyFilepath, "signer-name", cannedPasswordRetriever)) 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 ~/<trust_dir>/private/<key_id>.key file exists // check that the appropriate ~/<trust_dir>/private/<key_id>.key file exists
expectedImportKeyPath := filepath.Join(keyStorageDir, notary.PrivDir, privKeyID+"."+notary.KeyExtension) expectedImportKeyPath := filepath.Join(keyStorageDir, notary.PrivDir, privKeyID+"."+notary.KeyExtension)
_, err = os.Stat(expectedImportKeyPath) _, err = os.Stat(expectedImportKeyPath)
assert.Check(t, err) assert.NilError(t, err)
// verify the key content // verify the key content
from, _ := os.OpenFile(expectedImportKeyPath, os.O_RDONLY, notary.PrivExecPerms) 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)) assert.Check(t, is.Equal("ENCRYPTED PRIVATE KEY", keyPEM.Type))
decryptedKey, err := tufutils.ParsePKCS8ToTufKey(keyPEM.Bytes, []byte(passwd)) decryptedKey, err := tufutils.ParsePKCS8ToTufKey(keyPEM.Bytes, []byte(passwd))
assert.Check(t, err) assert.NilError(t, err)
fixturePEM, _ := pem.Decode(privKeyFixture) fixturePEM, _ := pem.Decode(privKeyFixture)
assert.Check(t, is.DeepEqual(fixturePEM.Bytes, decryptedKey.Private())) 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) { func testLoadKeyTooPermissive(t *testing.T, privKeyFixture []byte) {
privKeyDir, err := ioutil.TempDir("", "key-load-test-") privKeyDir, err := ioutil.TempDir("", "key-load-test-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(privKeyDir) defer os.RemoveAll(privKeyDir)
privKeyFilepath := filepath.Join(privKeyDir, "privkey477.pem") privKeyFilepath := filepath.Join(privKeyDir, "privkey477.pem")
assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0477)) assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0477))
keyStorageDir, err := ioutil.TempDir("", "loaded-keys-") keyStorageDir, err := ioutil.TempDir("", "loaded-keys-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(keyStorageDir) defer os.RemoveAll(keyStorageDir)
// import the key to our 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)) assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0400))
_, err = getPrivKeyBytesFromPath(privKeyFilepath) _, err = getPrivKeyBytesFromPath(privKeyFilepath)
assert.Check(t, err) assert.NilError(t, err)
privKeyFilepath = filepath.Join(privKeyDir, "privkey600.pem") privKeyFilepath = filepath.Join(privKeyDir, "privkey600.pem")
assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0600)) assert.Check(t, ioutil.WriteFile(privKeyFilepath, privKeyFixture, 0600))
_, err = getPrivKeyBytesFromPath(privKeyFilepath) _, err = getPrivKeyBytesFromPath(privKeyFilepath)
assert.Check(t, err) assert.NilError(t, err)
} }
var pubKeyFixture = []byte(`-----BEGIN PUBLIC KEY----- var pubKeyFixture = []byte(`-----BEGIN PUBLIC KEY-----
@ -220,22 +220,22 @@ H3nzy2O6Q/ct4BjOBKa+WCdRtPo78bA+C/7t81ADQO8Jqaj59W50rwoqDQ==
func TestLoadPubKeyFailure(t *testing.T) { func TestLoadPubKeyFailure(t *testing.T) {
pubKeyDir, err := ioutil.TempDir("", "key-load-test-pubkey-") pubKeyDir, err := ioutil.TempDir("", "key-load-test-pubkey-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(pubKeyDir) defer os.RemoveAll(pubKeyDir)
pubKeyFilepath := filepath.Join(pubKeyDir, "pubkey.pem") pubKeyFilepath := filepath.Join(pubKeyDir, "pubkey.pem")
assert.Check(t, ioutil.WriteFile(pubKeyFilepath, pubKeyFixture, notary.PrivNoExecPerms)) assert.Check(t, ioutil.WriteFile(pubKeyFilepath, pubKeyFixture, notary.PrivNoExecPerms))
keyStorageDir, err := ioutil.TempDir("", "loaded-keys-") keyStorageDir, err := ioutil.TempDir("", "loaded-keys-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(keyStorageDir) defer os.RemoveAll(keyStorageDir)
passwd := "password" passwd := "password"
cannedPasswordRetriever := passphrase.ConstantRetriever(passwd) cannedPasswordRetriever := passphrase.ConstantRetriever(passwd)
keyFileStore, err := storage.NewPrivateKeyFileStorage(keyStorageDir, notary.KeyExtension) keyFileStore, err := storage.NewPrivateKeyFileStorage(keyStorageDir, notary.KeyExtension)
assert.Check(t, err) assert.NilError(t, err)
privKeyImporters := []trustmanager.Importer{keyFileStore} privKeyImporters := []trustmanager.Importer{keyFileStore}
pubKeyBytes, err := getPrivKeyBytesFromPath(pubKeyFilepath) pubKeyBytes, err := getPrivKeyBytesFromPath(pubKeyFilepath)
assert.Check(t, err) assert.NilError(t, err)
// import the key to our keyStorageDir - it should fail // import the key to our keyStorageDir - it should fail
err = loadPrivKeyBytesToStore(pubKeyBytes, privKeyImporters, pubKeyFilepath, "signer-name", cannedPasswordRetriever) err = loadPrivKeyBytesToStore(pubKeyBytes, privKeyImporters, pubKeyFilepath, "signer-name", cannedPasswordRetriever)

View File

@ -136,7 +136,7 @@ func TestNewRevokeTrustAllSigConfirmation(t *testing.T) {
func TestGetSignableRolesForTargetAndRemoveError(t *testing.T) { func TestGetSignableRolesForTargetAndRemoveError(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "notary-test-") tmpDir, err := ioutil.TempDir("", "notary-test-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{}) notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{})

View File

@ -60,7 +60,7 @@ func TestTrustSignCommandErrors(t *testing.T) {
} }
// change to a tmpdir // change to a tmpdir
tmpDir, err := ioutil.TempDir("", "docker-sign-test-") tmpDir, err := ioutil.TempDir("", "docker-sign-test-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
config.SetDir(tmpDir) config.SetDir(tmpDir)
for _, tc := range testCases { for _, tc := range testCases {
@ -83,15 +83,15 @@ func TestTrustSignCommandOfflineErrors(t *testing.T) {
func TestGetOrGenerateNotaryKey(t *testing.T) { func TestGetOrGenerateNotaryKey(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "notary-test-") tmpDir, err := ioutil.TempDir("", "notary-test-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{}) 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 // repo is empty, try making a root key
rootKeyA, err := getOrGenerateNotaryKey(notaryRepo, data.CanonicalRootRole) rootKeyA, err := getOrGenerateNotaryKey(notaryRepo, data.CanonicalRootRole)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, rootKeyA != nil) assert.Check(t, rootKeyA != nil)
// we should only have one newly generated key // 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 // this time we should get back the same key if we ask for another root key
rootKeyB, err := getOrGenerateNotaryKey(notaryRepo, data.CanonicalRootRole) rootKeyB, err := getOrGenerateNotaryKey(notaryRepo, data.CanonicalRootRole)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, rootKeyB != nil) assert.Check(t, rootKeyB != nil)
// we should only have one newly generated key // we should only have one newly generated key
@ -114,7 +114,7 @@ func TestGetOrGenerateNotaryKey(t *testing.T) {
// Now also try with a delegation key // Now also try with a delegation key
releasesKey, err := getOrGenerateNotaryKey(notaryRepo, data.RoleName(trust.ReleasesRole)) releasesKey, err := getOrGenerateNotaryKey(notaryRepo, data.RoleName(trust.ReleasesRole))
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, releasesKey != nil) assert.Check(t, releasesKey != nil)
// we should now have two keys // we should now have two keys
@ -128,20 +128,20 @@ func TestGetOrGenerateNotaryKey(t *testing.T) {
func TestAddStageSigners(t *testing.T) { func TestAddStageSigners(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "notary-test-") tmpDir, err := ioutil.TempDir("", "notary-test-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{}) 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 // stage targets/user
userRole := data.RoleName("targets/user") userRole := data.RoleName("targets/user")
userKey := data.NewPublicKey("algoA", []byte("a")) userKey := data.NewPublicKey("algoA", []byte("a"))
err = addStagedSigner(notaryRepo, userRole, []data.PublicKey{userKey}) 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 // check the changelist for four total changes: two on targets/releases and two on targets/user
cl, err := notaryRepo.GetChangelist() cl, err := notaryRepo.GetChangelist()
assert.Check(t, err) assert.NilError(t, err)
changeList := cl.List() changeList := cl.List()
assert.Check(t, is.Len(changeList, 4)) assert.Check(t, is.Len(changeList, 4))
// ordering is determinstic: // ordering is determinstic:
@ -213,11 +213,11 @@ func TestAddStageSigners(t *testing.T) {
func TestGetSignedManifestHashAndSize(t *testing.T) { func TestGetSignedManifestHashAndSize(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "notary-test-") tmpDir, err := ioutil.TempDir("", "notary-test-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{}) 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 := &client.Target{}
target.Hashes, target.Length, err = getSignedManifestHashAndSize(notaryRepo, "test") target.Hashes, target.Length, err = getSignedManifestHashAndSize(notaryRepo, "test")
assert.Check(t, is.Error(err, "client is offline")) assert.Check(t, is.Error(err, "client is offline"))
@ -241,11 +241,11 @@ func TestGetReleasedTargetHashAndSize(t *testing.T) {
func TestCreateTarget(t *testing.T) { func TestCreateTarget(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "notary-test-") tmpDir, err := ioutil.TempDir("", "notary-test-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{}) 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, "") _, err = createTarget(notaryRepo, "")
assert.Check(t, is.Error(err, "No tag specified")) assert.Check(t, is.Error(err, "No tag specified"))
_, err = createTarget(notaryRepo, "1") _, err = createTarget(notaryRepo, "1")
@ -254,11 +254,11 @@ func TestCreateTarget(t *testing.T) {
func TestGetExistingSignatureInfoForReleasedTag(t *testing.T) { func TestGetExistingSignatureInfoForReleasedTag(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "notary-test-") tmpDir, err := ioutil.TempDir("", "notary-test-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{}) 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") _, err = getExistingSignatureInfoForReleasedTag(notaryRepo, "test")
assert.Check(t, is.Error(err, "client is offline")) assert.Check(t, is.Error(err, "client is offline"))
} }
@ -274,7 +274,7 @@ func TestPrettyPrintExistingSignatureInfo(t *testing.T) {
func TestSignCommandChangeListIsCleanedOnError(t *testing.T) { func TestSignCommandChangeListIsCleanedOnError(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "docker-sign-test-") tmpDir, err := ioutil.TempDir("", "docker-sign-test-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
config.SetDir(tmpDir) config.SetDir(tmpDir)
@ -288,7 +288,7 @@ func TestSignCommandChangeListIsCleanedOnError(t *testing.T) {
assert.Assert(t, is.ErrorContains(err, "")) assert.Assert(t, is.ErrorContains(err, ""))
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "docker.io/library/ubuntu", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{}) 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() cl, err := notaryRepo.GetChangelist()
assert.NilError(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(len(cl.List()), 0)) assert.Check(t, is.Equal(len(cl.List()), 0))

View File

@ -51,7 +51,7 @@ func TestTrustSignerAddErrors(t *testing.T) {
}, },
} }
tmpDir, err := ioutil.TempDir("", "docker-sign-test-") tmpDir, err := ioutil.TempDir("", "docker-sign-test-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
config.SetDir(tmpDir) config.SetDir(tmpDir)
@ -67,12 +67,12 @@ func TestTrustSignerAddErrors(t *testing.T) {
func TestSignerAddCommandNoTargetsKey(t *testing.T) { func TestSignerAddCommandNoTargetsKey(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "docker-sign-test-") tmpDir, err := ioutil.TempDir("", "docker-sign-test-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
config.SetDir(tmpDir) config.SetDir(tmpDir)
tmpfile, err := ioutil.TempFile("", "pemfile") tmpfile, err := ioutil.TempFile("", "pemfile")
assert.Check(t, err) assert.NilError(t, err)
defer os.Remove(tmpfile.Name()) defer os.Remove(tmpfile.Name())
cli := test.NewFakeCli(&fakeClient{}) cli := test.NewFakeCli(&fakeClient{})
@ -86,7 +86,7 @@ func TestSignerAddCommandNoTargetsKey(t *testing.T) {
func TestSignerAddCommandBadKeyPath(t *testing.T) { func TestSignerAddCommandBadKeyPath(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "docker-sign-test-") tmpDir, err := ioutil.TempDir("", "docker-sign-test-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
config.SetDir(tmpDir) config.SetDir(tmpDir)
@ -101,12 +101,12 @@ func TestSignerAddCommandBadKeyPath(t *testing.T) {
func TestSignerAddCommandInvalidRepoName(t *testing.T) { func TestSignerAddCommandInvalidRepoName(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "docker-sign-test-") tmpDir, err := ioutil.TempDir("", "docker-sign-test-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
config.SetDir(tmpDir) config.SetDir(tmpDir)
pubKeyDir, err := ioutil.TempDir("", "key-load-test-pubkey-") pubKeyDir, err := ioutil.TempDir("", "key-load-test-pubkey-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(pubKeyDir) defer os.RemoveAll(pubKeyDir)
pubKeyFilepath := filepath.Join(pubKeyDir, "pubkey.pem") pubKeyFilepath := filepath.Join(pubKeyDir, "pubkey.pem")
assert.Check(t, ioutil.WriteFile(pubKeyFilepath, pubKeyFixture, notary.PrivNoExecPerms)) 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")) 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 // Call with real file path
tmpfile, err := ioutil.TempFile("", "pemfile") tmpfile, err := ioutil.TempFile("", "pemfile")
assert.Check(t, err) assert.NilError(t, err)
defer os.Remove(tmpfile.Name()) defer os.Remove(tmpfile.Name())
_, err = ingestPublicKeys([]string{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()))) assert.Check(t, is.Error(err, fmt.Sprintf("could not parse public key from file: %s: no valid public key found", tmpfile.Name())))

View File

@ -90,7 +90,7 @@ func TestRemoveLastSignerWarning(t *testing.T) {
cli.SetNotaryClient(getLoadedNotaryRepository) cli.SetNotaryClient(getLoadedNotaryRepository)
err := removeSigner(cli, signerRemoveOptions{signer: "alice", repos: []string{"signed-repo"}, forceYes: false}) 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(), assert.Check(t, is.Contains(cli.OutBuffer().String(),
"The signer \"alice\" signed the last released version of signed-repo. "+ "The signer \"alice\" signed the last released version of signed-repo. "+
"Removing this signer will make signed-repo unpullable. "+ "Removing this signer will make signed-repo unpullable. "+

View File

@ -121,7 +121,7 @@ func TestSecrets(t *testing.T) {
} }
specs, err := Secrets(namespace, source) specs, err := Secrets(namespace, source)
assert.Check(t, err) assert.NilError(t, err)
assert.Assert(t, is.Len(specs, 1)) assert.Assert(t, is.Len(specs, 1))
secret := specs[0] secret := specs[0]
assert.Check(t, is.Equal("foo_one", secret.Name)) assert.Check(t, is.Equal("foo_one", secret.Name))
@ -152,7 +152,7 @@ func TestConfigs(t *testing.T) {
} }
specs, err := Configs(namespace, source) specs, err := Configs(namespace, source)
assert.Check(t, err) assert.NilError(t, err)
assert.Assert(t, is.Len(specs, 1)) assert.Assert(t, is.Len(specs, 1))
config := specs[0] config := specs[0]
assert.Check(t, is.Equal("foo_one", config.Name)) assert.Check(t, is.Equal("foo_one", config.Name))

View File

@ -20,7 +20,7 @@ import (
func TestConvertRestartPolicyFromNone(t *testing.T) { func TestConvertRestartPolicyFromNone(t *testing.T) {
policy, err := convertRestartPolicy("no", nil) policy, err := convertRestartPolicy("no", nil)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual((*swarm.RestartPolicy)(nil), policy)) assert.Check(t, is.DeepEqual((*swarm.RestartPolicy)(nil), policy))
} }
@ -34,7 +34,7 @@ func TestConvertRestartPolicyFromAlways(t *testing.T) {
expected := &swarm.RestartPolicy{ expected := &swarm.RestartPolicy{
Condition: swarm.RestartPolicyConditionAny, Condition: swarm.RestartPolicyConditionAny,
} }
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, policy)) assert.Check(t, is.DeepEqual(expected, policy))
} }
@ -45,7 +45,7 @@ func TestConvertRestartPolicyFromFailure(t *testing.T) {
Condition: swarm.RestartPolicyConditionOnFailure, Condition: swarm.RestartPolicyConditionOnFailure,
MaxAttempts: &attempts, MaxAttempts: &attempts,
} }
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, policy)) assert.Check(t, is.DeepEqual(expected, policy))
} }
@ -84,7 +84,7 @@ func TestConvertResourcesFull(t *testing.T) {
}, },
} }
resources, err := convertResources(source) resources, err := convertResources(source)
assert.Check(t, err) assert.NilError(t, err)
expected := &swarm.ResourceRequirements{ expected := &swarm.ResourceRequirements{
Limits: &swarm.Resources{ Limits: &swarm.Resources{
@ -109,7 +109,7 @@ func TestConvertResourcesOnlyMemory(t *testing.T) {
}, },
} }
resources, err := convertResources(source) resources, err := convertResources(source)
assert.Check(t, err) assert.NilError(t, err)
expected := &swarm.ResourceRequirements{ expected := &swarm.ResourceRequirements{
Limits: &swarm.Resources{ Limits: &swarm.Resources{
@ -140,7 +140,7 @@ func TestConvertHealthcheck(t *testing.T) {
} }
healthcheck, err := convertHealthcheck(source) healthcheck, err := convertHealthcheck(source)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, healthcheck)) assert.Check(t, is.DeepEqual(expected, healthcheck))
} }
@ -151,7 +151,7 @@ func TestConvertHealthcheckDisable(t *testing.T) {
} }
healthcheck, err := convertHealthcheck(source) healthcheck, err := convertHealthcheck(source)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, healthcheck)) 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)) 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)) assert.Check(t, is.DeepEqual(expected, configs))
} }
@ -250,7 +250,7 @@ func TestConvertServiceNetworks(t *testing.T) {
sortedConfigs := byTargetSort(configs) sortedConfigs := byTargetSort(configs)
sort.Sort(&sortedConfigs) sort.Sort(&sortedConfigs)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, []swarm.NetworkAttachmentConfig(sortedConfigs))) 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))) 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) { func TestConvertDNSConfigEmpty(t *testing.T) {
dnsConfig, err := convertDNSConfig(nil, nil) dnsConfig, err := convertDNSConfig(nil, nil)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual((*swarm.DNSConfig)(nil), dnsConfig)) assert.Check(t, is.DeepEqual((*swarm.DNSConfig)(nil), dnsConfig))
} }
@ -305,7 +305,7 @@ var (
func TestConvertDNSConfigAll(t *testing.T) { func TestConvertDNSConfigAll(t *testing.T) {
dnsConfig, err := convertDNSConfig(nameservers, search) dnsConfig, err := convertDNSConfig(nameservers, search)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(&swarm.DNSConfig{ assert.Check(t, is.DeepEqual(&swarm.DNSConfig{
Nameservers: nameservers, Nameservers: nameservers,
Search: search, Search: search,
@ -314,7 +314,7 @@ func TestConvertDNSConfigAll(t *testing.T) {
func TestConvertDNSConfigNameservers(t *testing.T) { func TestConvertDNSConfigNameservers(t *testing.T) {
dnsConfig, err := convertDNSConfig(nameservers, nil) dnsConfig, err := convertDNSConfig(nameservers, nil)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(&swarm.DNSConfig{ assert.Check(t, is.DeepEqual(&swarm.DNSConfig{
Nameservers: nameservers, Nameservers: nameservers,
Search: nil, Search: nil,
@ -323,7 +323,7 @@ func TestConvertDNSConfigNameservers(t *testing.T) {
func TestConvertDNSConfigSearch(t *testing.T) { func TestConvertDNSConfigSearch(t *testing.T) {
dnsConfig, err := convertDNSConfig(nil, search) dnsConfig, err := convertDNSConfig(nil, search)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(&swarm.DNSConfig{ assert.Check(t, is.DeepEqual(&swarm.DNSConfig{
Nameservers: nil, Nameservers: nil,
Search: search, Search: search,
@ -332,20 +332,20 @@ func TestConvertDNSConfigSearch(t *testing.T) {
func TestConvertCredentialSpec(t *testing.T) { func TestConvertCredentialSpec(t *testing.T) {
swarmSpec, err := convertCredentialSpec(composetypes.CredentialSpecConfig{}) swarmSpec, err := convertCredentialSpec(composetypes.CredentialSpecConfig{})
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Nil(swarmSpec)) assert.Check(t, is.Nil(swarmSpec))
swarmSpec, err = convertCredentialSpec(composetypes.CredentialSpecConfig{ swarmSpec, err = convertCredentialSpec(composetypes.CredentialSpecConfig{
File: "/foo", File: "/foo",
}) })
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(swarmSpec.File, "/foo")) assert.Check(t, is.Equal(swarmSpec.File, "/foo"))
assert.Check(t, is.Equal(swarmSpec.Registry, "")) assert.Check(t, is.Equal(swarmSpec.Registry, ""))
swarmSpec, err = convertCredentialSpec(composetypes.CredentialSpecConfig{ swarmSpec, err = convertCredentialSpec(composetypes.CredentialSpecConfig{
Registry: "foo", Registry: "foo",
}) })
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(swarmSpec.File, "")) assert.Check(t, is.Equal(swarmSpec.File, ""))
assert.Check(t, is.Equal(swarmSpec.Registry, "foo")) assert.Check(t, is.Equal(swarmSpec.Registry, "foo"))

View File

@ -19,7 +19,7 @@ func TestConvertVolumeToMountAnonymousVolume(t *testing.T) {
Target: "/foo/bar", Target: "/foo/bar",
} }
mount, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo")) mount, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo"))
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, mount)) assert.Check(t, is.DeepEqual(expected, mount))
} }
@ -174,7 +174,7 @@ func TestConvertVolumeToMountNamedVolume(t *testing.T) {
}, },
} }
mount, err := convertVolumeToMount(config, stackVolumes, namespace) mount, err := convertVolumeToMount(config, stackVolumes, namespace)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, mount)) assert.Check(t, is.DeepEqual(expected, mount))
} }
@ -221,7 +221,7 @@ func TestConvertVolumeToMountNamedVolumeWithNameCustomizd(t *testing.T) {
}, },
} }
mount, err := convertVolumeToMount(config, stackVolumes, namespace) mount, err := convertVolumeToMount(config, stackVolumes, namespace)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, mount)) assert.Check(t, is.DeepEqual(expected, mount))
} }
@ -245,7 +245,7 @@ func TestConvertVolumeToMountNamedVolumeExternal(t *testing.T) {
Target: "/foo", Target: "/foo",
} }
mount, err := convertVolumeToMount(config, stackVolumes, namespace) mount, err := convertVolumeToMount(config, stackVolumes, namespace)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, mount)) assert.Check(t, is.DeepEqual(expected, mount))
} }
@ -274,7 +274,7 @@ func TestConvertVolumeToMountNamedVolumeExternalNoCopy(t *testing.T) {
}, },
} }
mount, err := convertVolumeToMount(config, stackVolumes, namespace) mount, err := convertVolumeToMount(config, stackVolumes, namespace)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, mount)) assert.Check(t, is.DeepEqual(expected, mount))
} }
@ -296,7 +296,7 @@ func TestConvertVolumeToMountBind(t *testing.T) {
Bind: &composetypes.ServiceVolumeBind{Propagation: "shared"}, Bind: &composetypes.ServiceVolumeBind{Propagation: "shared"},
} }
mount, err := convertVolumeToMount(config, stackVolumes, namespace) mount, err := convertVolumeToMount(config, stackVolumes, namespace)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, mount)) assert.Check(t, is.DeepEqual(expected, mount))
} }
@ -326,7 +326,7 @@ func TestConvertTmpfsToMountVolume(t *testing.T) {
TmpfsOptions: &mount.TmpfsOptions{SizeBytes: 1000}, TmpfsOptions: &mount.TmpfsOptions{SizeBytes: 1000},
} }
mount, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo")) mount, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo"))
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, mount)) assert.Check(t, is.DeepEqual(expected, mount))
} }

View File

@ -47,7 +47,7 @@ func TestInterpolate(t *testing.T) {
}, },
} }
result, err := Interpolate(services, Options{LookupValue: defaultMapping}) result, err := Interpolate(services, Options{LookupValue: defaultMapping})
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, result)) assert.Check(t, is.DeepEqual(expected, result))
} }
@ -75,7 +75,7 @@ func TestInterpolateWithDefaults(t *testing.T) {
}, },
} }
result, err := Interpolate(config, Options{}) result, err := Interpolate(config, Options{})
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, result)) assert.Check(t, is.DeepEqual(expected, result))
} }
@ -92,7 +92,7 @@ func TestInterpolateWithCast(t *testing.T) {
LookupValue: defaultMapping, LookupValue: defaultMapping,
TypeCastMapping: map[Path]Cast{NewPath(PathMatchAll, "replicas"): toInt}, TypeCastMapping: map[Path]Cast{NewPath(PathMatchAll, "replicas"): toInt},
}) })
assert.Check(t, err) assert.NilError(t, err)
expected := map[string]interface{}{ expected := map[string]interface{}{
"foo": map[string]interface{}{ "foo": map[string]interface{}{
"replicas": 5, "replicas": 5,

View File

@ -410,7 +410,7 @@ services:
- QUX= - QUX=
- QUUX - QUUX
`, map[string]string{"QUX": "qux"}) `, map[string]string{"QUX": "qux"})
assert.Check(t, err) assert.NilError(t, err)
expected := types.MappingWithEquals{ expected := types.MappingWithEquals{
"FOO": strPtr("1"), "FOO": strPtr("1"),

View File

@ -319,12 +319,12 @@ configs: {}
` `
actual, err := yaml.Marshal(cfg) actual, err := yaml.Marshal(cfg)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(expected, string(actual))) assert.Check(t, is.Equal(expected, string(actual)))
// Make sure the expected still // Make sure the expected still
dict, err := ParseYAML([]byte("version: '3.6'\n" + expected)) dict, err := ParseYAML([]byte("version: '3.6'\n" + expected))
assert.Check(t, err) assert.NilError(t, err)
_, err = Load(buildConfigDetails(dict, map[string]string{})) _, err = Load(buildConfigDetails(dict, map[string]string{}))
assert.Check(t, err) assert.NilError(t, err)
} }

View File

@ -13,7 +13,7 @@ func TestParseVolumeAnonymousVolume(t *testing.T) {
for _, path := range []string{"/path", "/path/foo"} { for _, path := range []string{"/path", "/path/foo"} {
volume, err := ParseVolume(path) volume, err := ParseVolume(path)
expected := types.ServiceVolumeConfig{Type: "volume", Target: path} expected := types.ServiceVolumeConfig{Type: "volume", Target: path}
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, volume)) 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"} { for _, path := range []string{"C:\\path", "Z:\\path\\foo"} {
volume, err := ParseVolume(path) volume, err := ParseVolume(path)
expected := types.ServiceVolumeConfig{Type: "volume", Target: path} expected := types.ServiceVolumeConfig{Type: "volume", Target: path}
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, volume)) assert.Check(t, is.DeepEqual(expected, volume))
} }
} }
@ -36,7 +36,7 @@ func TestParseVolumeShortVolumes(t *testing.T) {
for _, path := range []string{".", "/a"} { for _, path := range []string{".", "/a"} {
volume, err := ParseVolume(path) volume, err := ParseVolume(path)
expected := types.ServiceVolumeConfig{Type: "volume", Target: path} expected := types.ServiceVolumeConfig{Type: "volume", Target: path}
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, volume)) assert.Check(t, is.DeepEqual(expected, volume))
} }
} }
@ -56,7 +56,7 @@ func TestParseVolumeBindMount(t *testing.T) {
Source: path, Source: path,
Target: "/target", Target: "/target",
} }
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, volume)) assert.Check(t, is.DeepEqual(expected, volume))
} }
} }
@ -74,7 +74,7 @@ func TestParseVolumeRelativeBindMountWindows(t *testing.T) {
Source: path, Source: path,
Target: "d:\\target", Target: "d:\\target",
} }
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, volume)) assert.Check(t, is.DeepEqual(expected, volume))
} }
} }
@ -87,7 +87,7 @@ func TestParseVolumeWithBindOptions(t *testing.T) {
Target: "/target", Target: "/target",
Bind: &types.ServiceVolumeBind{Propagation: "slave"}, Bind: &types.ServiceVolumeBind{Propagation: "slave"},
} }
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, volume)) assert.Check(t, is.DeepEqual(expected, volume))
} }
@ -100,13 +100,13 @@ func TestParseVolumeWithBindOptionsWindows(t *testing.T) {
ReadOnly: true, ReadOnly: true,
Bind: &types.ServiceVolumeBind{Propagation: "rprivate"}, Bind: &types.ServiceVolumeBind{Propagation: "rprivate"},
} }
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, volume)) assert.Check(t, is.DeepEqual(expected, volume))
} }
func TestParseVolumeWithInvalidVolumeOptions(t *testing.T) { func TestParseVolumeWithInvalidVolumeOptions(t *testing.T) {
_, err := ParseVolume("name:/target:bogus") _, err := ParseVolume("name:/target:bogus")
assert.Check(t, err) assert.NilError(t, err)
} }
func TestParseVolumeWithVolumeOptions(t *testing.T) { func TestParseVolumeWithVolumeOptions(t *testing.T) {
@ -117,7 +117,7 @@ func TestParseVolumeWithVolumeOptions(t *testing.T) {
Target: "/target", Target: "/target",
Volume: &types.ServiceVolumeVolume{NoCopy: true}, Volume: &types.ServiceVolumeVolume{NoCopy: true},
} }
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, volume)) assert.Check(t, is.DeepEqual(expected, volume))
} }
@ -130,7 +130,7 @@ func TestParseVolumeWithReadOnly(t *testing.T) {
Target: "/target", Target: "/target",
ReadOnly: true, ReadOnly: true,
} }
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, volume)) assert.Check(t, is.DeepEqual(expected, volume))
} }
} }
@ -144,7 +144,7 @@ func TestParseVolumeWithRW(t *testing.T) {
Target: "/target", Target: "/target",
ReadOnly: false, ReadOnly: false,
} }
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.DeepEqual(expected, volume)) assert.Check(t, is.DeepEqual(expected, volume))
} }
} }

View File

@ -42,7 +42,7 @@ func TestValidateAllowsXTopLevelFields(t *testing.T) {
} }
err := Validate(config, "3.4") err := Validate(config, "3.4")
assert.Check(t, err) assert.NilError(t, err)
} }
func TestValidateSecretConfigNames(t *testing.T) { func TestValidateSecretConfigNames(t *testing.T) {
@ -61,7 +61,7 @@ func TestValidateSecretConfigNames(t *testing.T) {
} }
err := Validate(config, "3.5") err := Validate(config, "3.5")
assert.Check(t, err) assert.NilError(t, err)
} }
func TestValidateInvalidVersion(t *testing.T) { func TestValidateInvalidVersion(t *testing.T) {

View File

@ -20,7 +20,7 @@ func defaultMapping(name string) (string, bool) {
func TestEscaped(t *testing.T) { func TestEscaped(t *testing.T) {
result, err := Substitute("$${foo}", defaultMapping) result, err := Substitute("$${foo}", defaultMapping)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal("${foo}", result)) assert.Check(t, is.Equal("${foo}", result))
} }
@ -50,7 +50,7 @@ func TestInvalid(t *testing.T) {
func TestNoValueNoDefault(t *testing.T) { func TestNoValueNoDefault(t *testing.T) {
for _, template := range []string{"This ${missing} var", "This ${BAR} var"} { for _, template := range []string{"This ${missing} var", "This ${BAR} var"} {
result, err := Substitute(template, defaultMapping) result, err := Substitute(template, defaultMapping)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal("This var", result)) assert.Check(t, is.Equal("This var", result))
} }
} }
@ -58,7 +58,7 @@ func TestNoValueNoDefault(t *testing.T) {
func TestValueNoDefault(t *testing.T) { func TestValueNoDefault(t *testing.T) {
for _, template := range []string{"This $FOO var", "This ${FOO} var"} { for _, template := range []string{"This $FOO var", "This ${FOO} var"} {
result, err := Substitute(template, defaultMapping) result, err := Substitute(template, defaultMapping)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal("This first var", result)) assert.Check(t, is.Equal("This first var", result))
} }
} }
@ -66,26 +66,26 @@ func TestValueNoDefault(t *testing.T) {
func TestNoValueWithDefault(t *testing.T) { func TestNoValueWithDefault(t *testing.T) {
for _, template := range []string{"ok ${missing:-def}", "ok ${missing-def}"} { for _, template := range []string{"ok ${missing:-def}", "ok ${missing-def}"} {
result, err := Substitute(template, defaultMapping) result, err := Substitute(template, defaultMapping)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal("ok def", result)) assert.Check(t, is.Equal("ok def", result))
} }
} }
func TestEmptyValueWithSoftDefault(t *testing.T) { func TestEmptyValueWithSoftDefault(t *testing.T) {
result, err := Substitute("ok ${BAR:-def}", defaultMapping) result, err := Substitute("ok ${BAR:-def}", defaultMapping)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal("ok def", result)) assert.Check(t, is.Equal("ok def", result))
} }
func TestEmptyValueWithHardDefault(t *testing.T) { func TestEmptyValueWithHardDefault(t *testing.T) {
result, err := Substitute("ok ${BAR-def}", defaultMapping) result, err := Substitute("ok ${BAR-def}", defaultMapping)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal("ok ", result)) assert.Check(t, is.Equal("ok ", result))
} }
func TestNonAlphanumericDefault(t *testing.T) { func TestNonAlphanumericDefault(t *testing.T) {
result, err := Substitute("ok ${BAR:-/non:-alphanumeric}", defaultMapping) 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)) assert.Check(t, is.Equal("ok /non:-alphanumeric", result))
} }
@ -144,7 +144,7 @@ func TestDefaultsForMandatoryVariables(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
result, err := Substitute(tc.template, defaultMapping) result, err := Substitute(tc.template, defaultMapping)
assert.Check(t, err) assert.NilError(t, err)
assert.Check(t, is.Equal(tc.expected, result)) assert.Check(t, is.Equal(tc.expected, result))
} }
} }

View File

@ -227,7 +227,7 @@ func TestNativeStoreGetMissingCredentials(t *testing.T) {
fileStore: NewFileStore(f), fileStore: NewFileStore(f),
} }
_, err := s.Get(missingCredsAddress) _, err := s.Get(missingCredsAddress)
assert.Check(t, err) assert.NilError(t, err)
} }
func TestNativeStoreGetInvalidAddress(t *testing.T) { func TestNativeStoreGetInvalidAddress(t *testing.T) {

View File

@ -20,7 +20,7 @@ func TestCommonOptionsInstallFlags(t *testing.T) {
"--tlscert=\"/foo/cert\"", "--tlscert=\"/foo/cert\"",
"--tlskey=\"/foo/key\"", "--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/cafile", opts.TLSOptions.CAFile))
assert.Check(t, is.Equal("/foo/cert", opts.TLSOptions.CertFile)) assert.Check(t, is.Equal("/foo/cert", opts.TLSOptions.CertFile))
assert.Check(t, is.Equal(opts.TLSOptions.KeyFile, "/foo/key")) assert.Check(t, is.Equal(opts.TLSOptions.KeyFile, "/foo/key"))
@ -36,7 +36,7 @@ func TestCommonOptionsInstallFlagsWithDefaults(t *testing.T) {
opts.InstallFlags(flags) opts.InstallFlags(flags)
err := flags.Parse([]string{}) 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("ca.pem"), opts.TLSOptions.CAFile))
assert.Check(t, is.Equal(defaultPath("cert.pem"), opts.TLSOptions.CertFile)) assert.Check(t, is.Equal(defaultPath("cert.pem"), opts.TLSOptions.CertFile))
assert.Check(t, is.Equal(defaultPath("key.pem"), opts.TLSOptions.KeyFile)) assert.Check(t, is.Equal(defaultPath("key.pem"), opts.TLSOptions.KeyFile))

View File

@ -16,41 +16,41 @@ import (
func TestGetTag(t *testing.T) { func TestGetTag(t *testing.T) {
ref, err := reference.ParseNormalizedNamed("ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2") ref, err := reference.ParseNormalizedNamed("ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2")
assert.Check(t, err) assert.NilError(t, err)
tag := getTag(ref) tag := getTag(ref)
assert.Check(t, is.Equal("", tag)) assert.Check(t, is.Equal("", tag))
ref, err = reference.ParseNormalizedNamed("alpine:latest") ref, err = reference.ParseNormalizedNamed("alpine:latest")
assert.Check(t, err) assert.NilError(t, err)
tag = getTag(ref) tag = getTag(ref)
assert.Check(t, is.Equal(tag, "latest")) assert.Check(t, is.Equal(tag, "latest"))
ref, err = reference.ParseNormalizedNamed("alpine") ref, err = reference.ParseNormalizedNamed("alpine")
assert.Check(t, err) assert.NilError(t, err)
tag = getTag(ref) tag = getTag(ref)
assert.Check(t, is.Equal(tag, "")) assert.Check(t, is.Equal(tag, ""))
} }
func TestGetDigest(t *testing.T) { func TestGetDigest(t *testing.T) {
ref, err := reference.ParseNormalizedNamed("ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2") ref, err := reference.ParseNormalizedNamed("ubuntu@sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2")
assert.Check(t, err) assert.NilError(t, err)
d := getDigest(ref) d := getDigest(ref)
assert.Check(t, is.Equal(digest.Digest("sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2"), d)) assert.Check(t, is.Equal(digest.Digest("sha256:45b23dee08af5e43a7fea6c4cf9c25ccf269ee113168c19722f87876677c5cb2"), d))
ref, err = reference.ParseNormalizedNamed("alpine:latest") ref, err = reference.ParseNormalizedNamed("alpine:latest")
assert.Check(t, err) assert.NilError(t, err)
d = getDigest(ref) d = getDigest(ref)
assert.Check(t, is.Equal(digest.Digest(""), d)) assert.Check(t, is.Equal(digest.Digest(""), d))
ref, err = reference.ParseNormalizedNamed("alpine") ref, err = reference.ParseNormalizedNamed("alpine")
assert.Check(t, err) assert.NilError(t, err)
d = getDigest(ref) d = getDigest(ref)
assert.Check(t, is.Equal(digest.Digest(""), d)) assert.Check(t, is.Equal(digest.Digest(""), d))
} }
func TestGetSignableRolesError(t *testing.T) { func TestGetSignableRolesError(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "notary-test-") tmpDir, err := ioutil.TempDir("", "notary-test-")
assert.Check(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{}) notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{})

View File

@ -19,7 +19,7 @@ func TestClientDebugEnabled(t *testing.T) {
cmd.Flags().Set("debug", "true") cmd.Flags().Set("debug", "true")
err := cmd.PersistentPreRunE(cmd, []string{}) 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("1", os.Getenv("DEBUG")))
assert.Check(t, is.Equal(logrus.DebugLevel, logrus.GetLevel())) assert.Check(t, is.Equal(logrus.DebugLevel, logrus.GetLevel()))
} }

View File

@ -11,7 +11,7 @@ import (
// GitHub #32120 // GitHub #32120
func TestParseJSONFunctions(t *testing.T) { func TestParseJSONFunctions(t *testing.T) {
tm, err := Parse(`{{json .Ports}}`) tm, err := Parse(`{{json .Ports}}`)
assert.Check(t, err) assert.NilError(t, err)
var b bytes.Buffer var b bytes.Buffer
assert.Check(t, tm.Execute(&b, map[string]string{"Ports": "0.0.0.0:2->8/udp"})) 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) { func TestParseStringFunctions(t *testing.T) {
tm, err := Parse(`{{join (split . ":") "/"}}`) tm, err := Parse(`{{join (split . ":") "/"}}`)
assert.Check(t, err) assert.NilError(t, err)
var b bytes.Buffer var b bytes.Buffer
assert.Check(t, tm.Execute(&b, "text:with:colon")) assert.Check(t, tm.Execute(&b, "text:with:colon"))
@ -31,7 +31,7 @@ func TestParseStringFunctions(t *testing.T) {
func TestNewParse(t *testing.T) { func TestNewParse(t *testing.T) {
tm, err := NewParse("foo", "this is a {{ . }}") tm, err := NewParse("foo", "this is a {{ . }}")
assert.Check(t, err) assert.NilError(t, err)
var b bytes.Buffer var b bytes.Buffer
assert.Check(t, tm.Execute(&b, "string")) assert.Check(t, tm.Execute(&b, "string"))
@ -66,7 +66,7 @@ func TestParseTruncateFunction(t *testing.T) {
for _, testCase := range testCases { for _, testCase := range testCases {
tm, err := Parse(testCase.template) 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) { t.Run("Non Empty Source Test with template: "+testCase.template, func(t *testing.T) {
var b bytes.Buffer var b bytes.Buffer