-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor trust view command into a --pretty flag on trust inspect #934
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,24 +17,21 @@ import ( | |
"github.com/theupdateframework/notary/tuf/data" | ||
) | ||
|
||
/* TODO(n4ss): remove common tests with the regular inspect command */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same nit about comment |
||
|
||
type fakeClient struct { | ||
dockerClient.Client | ||
} | ||
|
||
func TestTrustViewCommandErrors(t *testing.T) { | ||
func TestTrustInspectPrettyCommandErrors(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
args []string | ||
expectedError string | ||
}{ | ||
{ | ||
name: "not-enough-args", | ||
expectedError: "requires exactly 1 argument", | ||
}, | ||
{ | ||
name: "too-many-args", | ||
args: []string{"remote1", "remote2"}, | ||
expectedError: "requires exactly 1 argument", | ||
expectedError: "requires at least 1 argument", | ||
}, | ||
{ | ||
name: "sha-reference", | ||
|
@@ -48,50 +45,56 @@ func TestTrustViewCommandErrors(t *testing.T) { | |
}, | ||
} | ||
for _, tc := range testCases { | ||
cmd := newViewCommand( | ||
cmd := newInspectCommand( | ||
test.NewFakeCli(&fakeClient{})) | ||
cmd.SetArgs(tc.args) | ||
cmd.SetOutput(ioutil.Discard) | ||
cmd.Flags().Set("pretty", "true") | ||
assert.ErrorContains(t, cmd.Execute(), tc.expectedError) | ||
} | ||
} | ||
|
||
func TestTrustViewCommandOfflineErrors(t *testing.T) { | ||
func TestTrustInspectPrettyCommandOfflineErrors(t *testing.T) { | ||
cli := test.NewFakeCli(&fakeClient{}) | ||
cli.SetNotaryClient(notaryfake.GetOfflineNotaryRepository) | ||
cmd := newViewCommand(cli) | ||
cmd := newInspectCommand(cli) | ||
cmd.Flags().Set("pretty", "true") | ||
cmd.SetArgs([]string{"nonexistent-reg-name.io/image"}) | ||
cmd.SetOutput(ioutil.Discard) | ||
assert.ErrorContains(t, cmd.Execute(), "No signatures or cannot access nonexistent-reg-name.io/image") | ||
|
||
cli = test.NewFakeCli(&fakeClient{}) | ||
cli.SetNotaryClient(notaryfake.GetOfflineNotaryRepository) | ||
cmd = newViewCommand(cli) | ||
cmd := newInspectCommand(cli) | ||
cmd.Flags().Set("pretty", "true") | ||
cmd.SetArgs([]string{"nonexistent-reg-name.io/image:tag"}) | ||
cmd.SetOutput(ioutil.Discard) | ||
assert.ErrorContains(t, cmd.Execute(), "No signatures or cannot access nonexistent-reg-name.io/image") | ||
} | ||
|
||
func TestTrustViewCommandUninitializedErrors(t *testing.T) { | ||
func TestTrustInspectPrettyCommandUninitializedErrors(t *testing.T) { | ||
cli := test.NewFakeCli(&fakeClient{}) | ||
cli.SetNotaryClient(notaryfake.GetUninitializedNotaryRepository) | ||
cmd := newViewCommand(cli) | ||
cmd := newInspectCommand(cli) | ||
cmd.Flags().Set("pretty", "true") | ||
cmd.SetArgs([]string{"reg/unsigned-img"}) | ||
cmd.SetOutput(ioutil.Discard) | ||
assert.ErrorContains(t, cmd.Execute(), "No signatures or cannot access reg/unsigned-img") | ||
|
||
cli = test.NewFakeCli(&fakeClient{}) | ||
cli.SetNotaryClient(notaryfake.GetUninitializedNotaryRepository) | ||
cmd = newViewCommand(cli) | ||
cmd := newInspectCommand(cli) | ||
cmd.Flags().Set("pretty", "true") | ||
cmd.SetArgs([]string{"reg/unsigned-img:tag"}) | ||
cmd.SetOutput(ioutil.Discard) | ||
assert.ErrorContains(t, cmd.Execute(), "No signatures or cannot access reg/unsigned-img:tag") | ||
} | ||
|
||
func TestTrustViewCommandEmptyNotaryRepoErrors(t *testing.T) { | ||
func TestTrustInspectPrettyCommandEmptyNotaryRepoErrors(t *testing.T) { | ||
cli := test.NewFakeCli(&fakeClient{}) | ||
cli.SetNotaryClient(notaryfake.GetEmptyTargetsNotaryRepository) | ||
cmd := newViewCommand(cli) | ||
cmd := newInspectCommand(cli) | ||
cmd.Flags().Set("pretty", "true") | ||
cmd.SetArgs([]string{"reg/img:unsigned-tag"}) | ||
cmd.SetOutput(ioutil.Discard) | ||
assert.NilError(t, cmd.Execute()) | ||
|
@@ -100,52 +103,57 @@ func TestTrustViewCommandEmptyNotaryRepoErrors(t *testing.T) { | |
|
||
cli = test.NewFakeCli(&fakeClient{}) | ||
cli.SetNotaryClient(notaryfake.GetEmptyTargetsNotaryRepository) | ||
cmd = newViewCommand(cli) | ||
cmd := newInspectCommand(cli) | ||
cmd.Flags().Set("pretty", "true") | ||
cmd.SetArgs([]string{"reg/img"}) | ||
cmd.SetOutput(ioutil.Discard) | ||
assert.NilError(t, cmd.Execute()) | ||
assert.Check(t, is.Contains(cli.OutBuffer().String(), "No signatures for reg/img")) | ||
assert.Check(t, is.Contains(cli.OutBuffer().String(), "Administrative keys for reg/img:")) | ||
} | ||
|
||
func TestTrustViewCommandFullRepoWithoutSigners(t *testing.T) { | ||
func TestTrustInspectPrettyCommandFullRepoWithoutSigners(t *testing.T) { | ||
cli := test.NewFakeCli(&fakeClient{}) | ||
cli.SetNotaryClient(notaryfake.GetLoadedWithNoSignersNotaryRepository) | ||
cmd := newViewCommand(cli) | ||
cmd := newInspectCommand(cli) | ||
cmd.Flags().Set("pretty", "true") | ||
cmd.SetArgs([]string{"signed-repo"}) | ||
assert.NilError(t, cmd.Execute()) | ||
|
||
golden.Assert(t, cli.OutBuffer().String(), "trust-view-full-repo-no-signers.golden") | ||
golden.Assert(t, cli.OutBuffer().String(), "trust-inspect-pretty-full-repo-no-signers.golden") | ||
} | ||
|
||
func TestTrustViewCommandOneTagWithoutSigners(t *testing.T) { | ||
func TestTrustInspectPrettyCommandOneTagWithoutSigners(t *testing.T) { | ||
cli := test.NewFakeCli(&fakeClient{}) | ||
cli.SetNotaryClient(notaryfake.GetLoadedWithNoSignersNotaryRepository) | ||
cmd := newViewCommand(cli) | ||
cmd := newInspectCommand(cli) | ||
cmd.Flags().Set("pretty", "true") | ||
cmd.SetArgs([]string{"signed-repo:green"}) | ||
assert.NilError(t, cmd.Execute()) | ||
|
||
golden.Assert(t, cli.OutBuffer().String(), "trust-view-one-tag-no-signers.golden") | ||
golden.Assert(t, cli.OutBuffer().String(), "trust-inspect-pretty-one-tag-no-signers.golden") | ||
} | ||
|
||
func TestTrustViewCommandFullRepoWithSigners(t *testing.T) { | ||
func TestTrustInspectPrettyCommandFullRepoWithSigners(t *testing.T) { | ||
cli := test.NewFakeCli(&fakeClient{}) | ||
cli.SetNotaryClient(notaryfake.GetLoadedNotaryRepository) | ||
cmd := newViewCommand(cli) | ||
cmd := newInspectCommand(cli) | ||
cmd.Flags().Set("pretty", "true") | ||
cmd.SetArgs([]string{"signed-repo"}) | ||
assert.NilError(t, cmd.Execute()) | ||
|
||
golden.Assert(t, cli.OutBuffer().String(), "trust-view-full-repo-with-signers.golden") | ||
golden.Assert(t, cli.OutBuffer().String(), "trust-inspect-pretty-full-repo-with-signers.golden") | ||
} | ||
|
||
func TestTrustViewCommandUnsignedTagInSignedRepo(t *testing.T) { | ||
func TestTrustInspectPrettyCommandUnsignedTagInSignedRepo(t *testing.T) { | ||
cli := test.NewFakeCli(&fakeClient{}) | ||
cli.SetNotaryClient(notaryfake.GetLoadedNotaryRepository) | ||
cmd := newViewCommand(cli) | ||
cmd := newInspectCommand(cli) | ||
cmd.Flags().Set("pretty", "true") | ||
cmd.SetArgs([]string{"signed-repo:unsigned"}) | ||
assert.NilError(t, cmd.Execute()) | ||
|
||
golden.Assert(t, cli.OutBuffer().String(), "trust-view-unsigned-tag-with-signers.golden") | ||
golden.Assert(t, cli.OutBuffer().String(), "trust-inspect-pretty-unsigned-tag-with-signers.golden") | ||
} | ||
|
||
func TestNotaryRoleToSigner(t *testing.T) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 7 additions & 3 deletions
10
...ta/trust-view-full-repo-no-signers.golden → ...nspect-pretty-full-repo-no-signers.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
|
||
Signatures for signed-repo | ||
|
||
SIGNED TAG DIGEST SIGNERS | ||
green 677265656e2d646967657374 (Repo Admin) | ||
|
||
Administrative keys for signed-repo: | ||
Repository Key: targetsID | ||
Root Key: rootID | ||
Administrative keys for signed-repo | ||
|
||
Repository Key: targetsID | ||
Root Key: rootID |
12 changes: 8 additions & 4 deletions
12
.../trust-view-full-repo-with-signers.golden → ...pect-pretty-full-repo-with-signers.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
|
||
Signatures for signed-repo | ||
|
||
SIGNED TAG DIGEST SIGNERS | ||
blue 626c75652d646967657374 alice | ||
green 677265656e2d646967657374 (Repo Admin) | ||
red 7265642d646967657374 alice, bob | ||
|
||
List of signers and their keys for signed-repo: | ||
List of signers and their keys for signed-repo | ||
|
||
SIGNER KEYS | ||
alice A | ||
bob B | ||
|
||
Administrative keys for signed-repo: | ||
Repository Key: targetsID | ||
Root Key: rootID | ||
Administrative keys for signed-repo | ||
|
||
Repository Key: targetsID | ||
Root Key: rootID |
10 changes: 10 additions & 0 deletions
10
cli/command/trust/testdata/trust-inspect-pretty-one-tag-no-signers.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
Signatures for signed-repo:green | ||
|
||
SIGNED TAG DIGEST SIGNERS | ||
green 677265656e2d646967657374 (Repo Admin) | ||
|
||
Administrative keys for signed-repo:green | ||
|
||
Repository Key: targetsID | ||
Root Key: rootID |
14 changes: 14 additions & 0 deletions
14
cli/command/trust/testdata/trust-inspect-pretty-unsigned-tag-with-signers.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
No signatures for signed-repo:unsigned | ||
|
||
|
||
List of signers and their keys for signed-repo:unsigned | ||
|
||
SIGNER KEYS | ||
alice A | ||
bob B | ||
|
||
Administrative keys for signed-repo:unsigned | ||
|
||
Repository Key: targetsID | ||
Root Key: rootID |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go comments are generally done with
//
even if they are multi-line./* */
is only used for package comments.