Fix comment and misc code issues

Signed-off-by: Nassim 'Nass' Eddequiouaq <eddequiouaq.nassim@gmail.com>
This commit is contained in:
Nassim 'Nass' Eddequiouaq 2018-03-09 20:26:43 +01:00
parent c5554f811b
commit 8c3d0b93d6
2 changed files with 10 additions and 11 deletions

View File

@ -14,9 +14,8 @@ import (
type inspectOptions struct { type inspectOptions struct {
remotes []string remotes []string
/* FIXME(n4ss): this is consistent with `docker service inspect` but we should provide // FIXME(n4ss): this is consistent with `docker service inspect` but we should provide
* a `--format` flag too. (format and pretty-print should be exclusive) // a `--format` flag too. (format and pretty-print should be exclusive)
*/
prettyPrint bool prettyPrint bool
} }
@ -41,7 +40,7 @@ func newInspectCommand(dockerCli command.Cli) *cobra.Command {
func runInspect(dockerCli command.Cli, opts inspectOptions) error { func runInspect(dockerCli command.Cli, opts inspectOptions) error {
if opts.prettyPrint { if opts.prettyPrint {
var err error = nil var err error
for index, remote := range opts.remotes { for index, remote := range opts.remotes {
if err = prettyPrintTrustInfo(dockerCli, remote); err != nil { if err = prettyPrintTrustInfo(dockerCli, remote); err != nil {
@ -49,7 +48,7 @@ func runInspect(dockerCli command.Cli, opts inspectOptions) error {
} }
// Additional separator between the inspection output of each image // Additional separator between the inspection output of each image
if index < len(opts.remotes) - 1 { if index < len(opts.remotes)-1 {
fmt.Fprint(dockerCli.Out(), "\n\n") fmt.Fprint(dockerCli.Out(), "\n\n")
} }
} }

View File

@ -17,7 +17,7 @@ import (
"github.com/theupdateframework/notary/tuf/data" "github.com/theupdateframework/notary/tuf/data"
) )
/* TODO(n4ss): remove common tests with the regular inspect command */ // TODO(n4ss): remove common tests with the regular inspect command
type fakeClient struct { type fakeClient struct {
dockerClient.Client dockerClient.Client
@ -65,7 +65,7 @@ func TestTrustInspectPrettyCommandOfflineErrors(t *testing.T) {
cli = test.NewFakeCli(&fakeClient{}) cli = test.NewFakeCli(&fakeClient{})
cli.SetNotaryClient(notaryfake.GetOfflineNotaryRepository) cli.SetNotaryClient(notaryfake.GetOfflineNotaryRepository)
cmd := newInspectCommand(cli) cmd = newInspectCommand(cli)
cmd.Flags().Set("pretty", "true") cmd.Flags().Set("pretty", "true")
cmd.SetArgs([]string{"nonexistent-reg-name.io/image:tag"}) cmd.SetArgs([]string{"nonexistent-reg-name.io/image:tag"})
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
@ -83,7 +83,7 @@ func TestTrustInspectPrettyCommandUninitializedErrors(t *testing.T) {
cli = test.NewFakeCli(&fakeClient{}) cli = test.NewFakeCli(&fakeClient{})
cli.SetNotaryClient(notaryfake.GetUninitializedNotaryRepository) cli.SetNotaryClient(notaryfake.GetUninitializedNotaryRepository)
cmd := newInspectCommand(cli) cmd = newInspectCommand(cli)
cmd.Flags().Set("pretty", "true") cmd.Flags().Set("pretty", "true")
cmd.SetArgs([]string{"reg/unsigned-img:tag"}) cmd.SetArgs([]string{"reg/unsigned-img:tag"})
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
@ -99,17 +99,17 @@ func TestTrustInspectPrettyCommandEmptyNotaryRepoErrors(t *testing.T) {
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
assert.NilError(t, cmd.Execute()) assert.NilError(t, cmd.Execute())
assert.Check(t, is.Contains(cli.OutBuffer().String(), "No signatures for reg/img:unsigned-tag")) assert.Check(t, is.Contains(cli.OutBuffer().String(), "No signatures for reg/img:unsigned-tag"))
assert.Check(t, is.Contains(cli.OutBuffer().String(), "Administrative keys for reg/img:")) assert.Check(t, is.Contains(cli.OutBuffer().String(), "Administrative keys for reg/img"))
cli = test.NewFakeCli(&fakeClient{}) cli = test.NewFakeCli(&fakeClient{})
cli.SetNotaryClient(notaryfake.GetEmptyTargetsNotaryRepository) cli.SetNotaryClient(notaryfake.GetEmptyTargetsNotaryRepository)
cmd := newInspectCommand(cli) cmd = newInspectCommand(cli)
cmd.Flags().Set("pretty", "true") cmd.Flags().Set("pretty", "true")
cmd.SetArgs([]string{"reg/img"}) cmd.SetArgs([]string{"reg/img"})
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
assert.NilError(t, cmd.Execute()) assert.NilError(t, cmd.Execute())
assert.Check(t, is.Contains(cli.OutBuffer().String(), "No signatures for reg/img")) assert.Check(t, is.Contains(cli.OutBuffer().String(), "No signatures for reg/img"))
assert.Check(t, is.Contains(cli.OutBuffer().String(), "Administrative keys for reg/img:")) assert.Check(t, is.Contains(cli.OutBuffer().String(), "Administrative keys for reg/img"))
} }
func TestTrustInspectPrettyCommandFullRepoWithoutSigners(t *testing.T) { func TestTrustInspectPrettyCommandFullRepoWithoutSigners(t *testing.T) {