@@ -17,24 +17,21 @@ import (
1717 "github.com/theupdateframework/notary/tuf/data"
1818)
1919
20+ // TODO(n4ss): remove common tests with the regular inspect command
21+
2022type fakeClient struct {
2123 dockerClient.Client
2224}
2325
24- func TestTrustViewCommandErrors (t * testing.T ) {
26+ func TestTrustInspectPrettyCommandErrors (t * testing.T ) {
2527 testCases := []struct {
2628 name string
2729 args []string
2830 expectedError string
2931 }{
3032 {
3133 name : "not-enough-args" ,
32- expectedError : "requires exactly 1 argument" ,
33- },
34- {
35- name : "too-many-args" ,
36- args : []string {"remote1" , "remote2" },
37- expectedError : "requires exactly 1 argument" ,
34+ expectedError : "requires at least 1 argument" ,
3835 },
3936 {
4037 name : "sha-reference" ,
@@ -48,104 +45,115 @@ func TestTrustViewCommandErrors(t *testing.T) {
4845 },
4946 }
5047 for _ , tc := range testCases {
51- cmd := newViewCommand (
48+ cmd := newInspectCommand (
5249 test .NewFakeCli (& fakeClient {}))
5350 cmd .SetArgs (tc .args )
5451 cmd .SetOutput (ioutil .Discard )
52+ cmd .Flags ().Set ("pretty" , "true" )
5553 assert .ErrorContains (t , cmd .Execute (), tc .expectedError )
5654 }
5755}
5856
59- func TestTrustViewCommandOfflineErrors (t * testing.T ) {
57+ func TestTrustInspectPrettyCommandOfflineErrors (t * testing.T ) {
6058 cli := test .NewFakeCli (& fakeClient {})
6159 cli .SetNotaryClient (notaryfake .GetOfflineNotaryRepository )
62- cmd := newViewCommand (cli )
60+ cmd := newInspectCommand (cli )
61+ cmd .Flags ().Set ("pretty" , "true" )
6362 cmd .SetArgs ([]string {"nonexistent-reg-name.io/image" })
6463 cmd .SetOutput (ioutil .Discard )
6564 assert .ErrorContains (t , cmd .Execute (), "No signatures or cannot access nonexistent-reg-name.io/image" )
6665
6766 cli = test .NewFakeCli (& fakeClient {})
6867 cli .SetNotaryClient (notaryfake .GetOfflineNotaryRepository )
69- cmd = newViewCommand (cli )
68+ cmd = newInspectCommand (cli )
69+ cmd .Flags ().Set ("pretty" , "true" )
7070 cmd .SetArgs ([]string {"nonexistent-reg-name.io/image:tag" })
7171 cmd .SetOutput (ioutil .Discard )
7272 assert .ErrorContains (t , cmd .Execute (), "No signatures or cannot access nonexistent-reg-name.io/image" )
7373}
7474
75- func TestTrustViewCommandUninitializedErrors (t * testing.T ) {
75+ func TestTrustInspectPrettyCommandUninitializedErrors (t * testing.T ) {
7676 cli := test .NewFakeCli (& fakeClient {})
7777 cli .SetNotaryClient (notaryfake .GetUninitializedNotaryRepository )
78- cmd := newViewCommand (cli )
78+ cmd := newInspectCommand (cli )
79+ cmd .Flags ().Set ("pretty" , "true" )
7980 cmd .SetArgs ([]string {"reg/unsigned-img" })
8081 cmd .SetOutput (ioutil .Discard )
8182 assert .ErrorContains (t , cmd .Execute (), "No signatures or cannot access reg/unsigned-img" )
8283
8384 cli = test .NewFakeCli (& fakeClient {})
8485 cli .SetNotaryClient (notaryfake .GetUninitializedNotaryRepository )
85- cmd = newViewCommand (cli )
86+ cmd = newInspectCommand (cli )
87+ cmd .Flags ().Set ("pretty" , "true" )
8688 cmd .SetArgs ([]string {"reg/unsigned-img:tag" })
8789 cmd .SetOutput (ioutil .Discard )
8890 assert .ErrorContains (t , cmd .Execute (), "No signatures or cannot access reg/unsigned-img:tag" )
8991}
9092
91- func TestTrustViewCommandEmptyNotaryRepoErrors (t * testing.T ) {
93+ func TestTrustInspectPrettyCommandEmptyNotaryRepoErrors (t * testing.T ) {
9294 cli := test .NewFakeCli (& fakeClient {})
9395 cli .SetNotaryClient (notaryfake .GetEmptyTargetsNotaryRepository )
94- cmd := newViewCommand (cli )
96+ cmd := newInspectCommand (cli )
97+ cmd .Flags ().Set ("pretty" , "true" )
9598 cmd .SetArgs ([]string {"reg/img:unsigned-tag" })
9699 cmd .SetOutput (ioutil .Discard )
97100 assert .NilError (t , cmd .Execute ())
98101 assert .Check (t , is .Contains (cli .OutBuffer ().String (), "No signatures for reg/img:unsigned-tag" ))
99- assert .Check (t , is .Contains (cli .OutBuffer ().String (), "Administrative keys for reg/img: " ))
102+ assert .Check (t , is .Contains (cli .OutBuffer ().String (), "Administrative keys for reg/img" ))
100103
101104 cli = test .NewFakeCli (& fakeClient {})
102105 cli .SetNotaryClient (notaryfake .GetEmptyTargetsNotaryRepository )
103- cmd = newViewCommand (cli )
106+ cmd = newInspectCommand (cli )
107+ cmd .Flags ().Set ("pretty" , "true" )
104108 cmd .SetArgs ([]string {"reg/img" })
105109 cmd .SetOutput (ioutil .Discard )
106110 assert .NilError (t , cmd .Execute ())
107111 assert .Check (t , is .Contains (cli .OutBuffer ().String (), "No signatures for reg/img" ))
108- assert .Check (t , is .Contains (cli .OutBuffer ().String (), "Administrative keys for reg/img: " ))
112+ assert .Check (t , is .Contains (cli .OutBuffer ().String (), "Administrative keys for reg/img" ))
109113}
110114
111- func TestTrustViewCommandFullRepoWithoutSigners (t * testing.T ) {
115+ func TestTrustInspectPrettyCommandFullRepoWithoutSigners (t * testing.T ) {
112116 cli := test .NewFakeCli (& fakeClient {})
113117 cli .SetNotaryClient (notaryfake .GetLoadedWithNoSignersNotaryRepository )
114- cmd := newViewCommand (cli )
118+ cmd := newInspectCommand (cli )
119+ cmd .Flags ().Set ("pretty" , "true" )
115120 cmd .SetArgs ([]string {"signed-repo" })
116121 assert .NilError (t , cmd .Execute ())
117122
118- golden .Assert (t , cli .OutBuffer ().String (), "trust-view -full-repo-no-signers.golden" )
123+ golden .Assert (t , cli .OutBuffer ().String (), "trust-inspect-pretty -full-repo-no-signers.golden" )
119124}
120125
121- func TestTrustViewCommandOneTagWithoutSigners (t * testing.T ) {
126+ func TestTrustInspectPrettyCommandOneTagWithoutSigners (t * testing.T ) {
122127 cli := test .NewFakeCli (& fakeClient {})
123128 cli .SetNotaryClient (notaryfake .GetLoadedWithNoSignersNotaryRepository )
124- cmd := newViewCommand (cli )
129+ cmd := newInspectCommand (cli )
130+ cmd .Flags ().Set ("pretty" , "true" )
125131 cmd .SetArgs ([]string {"signed-repo:green" })
126132 assert .NilError (t , cmd .Execute ())
127133
128- golden .Assert (t , cli .OutBuffer ().String (), "trust-view -one-tag-no-signers.golden" )
134+ golden .Assert (t , cli .OutBuffer ().String (), "trust-inspect-pretty -one-tag-no-signers.golden" )
129135}
130136
131- func TestTrustViewCommandFullRepoWithSigners (t * testing.T ) {
137+ func TestTrustInspectPrettyCommandFullRepoWithSigners (t * testing.T ) {
132138 cli := test .NewFakeCli (& fakeClient {})
133139 cli .SetNotaryClient (notaryfake .GetLoadedNotaryRepository )
134- cmd := newViewCommand (cli )
140+ cmd := newInspectCommand (cli )
141+ cmd .Flags ().Set ("pretty" , "true" )
135142 cmd .SetArgs ([]string {"signed-repo" })
136143 assert .NilError (t , cmd .Execute ())
137144
138- golden .Assert (t , cli .OutBuffer ().String (), "trust-view -full-repo-with-signers.golden" )
145+ golden .Assert (t , cli .OutBuffer ().String (), "trust-inspect-pretty -full-repo-with-signers.golden" )
139146}
140147
141- func TestTrustViewCommandUnsignedTagInSignedRepo (t * testing.T ) {
148+ func TestTrustInspectPrettyCommandUnsignedTagInSignedRepo (t * testing.T ) {
142149 cli := test .NewFakeCli (& fakeClient {})
143150 cli .SetNotaryClient (notaryfake .GetLoadedNotaryRepository )
144- cmd := newViewCommand (cli )
151+ cmd := newInspectCommand (cli )
152+ cmd .Flags ().Set ("pretty" , "true" )
145153 cmd .SetArgs ([]string {"signed-repo:unsigned" })
146154 assert .NilError (t , cmd .Execute ())
147155
148- golden .Assert (t , cli .OutBuffer ().String (), "trust-view -unsigned-tag-with-signers.golden" )
156+ golden .Assert (t , cli .OutBuffer ().String (), "trust-inspect-pretty -unsigned-tag-with-signers.golden" )
149157}
150158
151159func TestNotaryRoleToSigner (t * testing.T ) {
0 commit comments