@@ -19,6 +19,7 @@ type GetAttestationCommandTestSuite struct {
1919 artifactPath string
2020 fingerprint string
2121 trailName string
22+ attestationId string
2223}
2324
2425func (suite * GetAttestationCommandTestSuite ) SetupTest () {
@@ -46,69 +47,117 @@ func (suite *GetAttestationCommandTestSuite) SetupTest() {
4647 CreateGenericTrailAttestation (suite .flowName , suite .trailName , "first-trail-attestation" , suite .Suite .T ())
4748 CreateGenericArtifactAttestation (suite .flowName , suite .trailName , suite .fingerprint , "second-artifact-attestation" , true , suite .Suite .T ())
4849 CreateGenericTrailAttestation (suite .flowName , suite .trailName , "second-trail-attestation" , suite .Suite .T ())
50+
51+ suite .attestationId = GetAttestationId (suite .flowName , suite .trailName , "first-trail-attestation" , suite .Suite .T ())
4952}
5053
5154func (suite * GetAttestationCommandTestSuite ) TestGetAttestationCmd () {
5255 tests := []cmdTestCase {
5356 {
5457 wantError : false ,
55- name : "if no attestation found, say so" ,
58+ name : "01 if no attestation found when getting by name , say so" ,
5659 cmd : fmt .Sprintf (`get attestation non-existent-attestation --flow %s --trail %s %s` , suite .flowName , suite .trailName , suite .defaultKosliArguments ),
5760 golden : "No attestations found.\n " ,
5861 },
5962 {
6063 wantError : false ,
61- name : "if no attestation found return empty list in json format" ,
64+ name : "02 if no attestation found when getting by name return empty list in json format" ,
6265 cmd : fmt .Sprintf (`get attestation non-existent-attestation --flow %s --trail %s %s --output json` , suite .flowName , suite .trailName , suite .defaultKosliArguments ),
6366 goldenJson : []jsonCheck {{"" , "[]" }},
6467 },
6568 {
6669 wantError : true ,
67- name : "providing more than one argument fails" ,
70+ name : "03 providing more than one argument fails" ,
6871 cmd : fmt .Sprintf (`get attestation first-attestation second-attestation --flow %s --trail %s %s` , suite .flowName , suite .trailName , suite .defaultKosliArguments ),
69- golden : "Error: accepts 1 arg(s), received 2\n " ,
72+ golden : "Error: accepts at most 1 arg(s), received 2\n " ,
7073 },
7174 {
7275 wantError : true ,
73- name : "missing --flow fails" ,
76+ name : "04 missing --flow fails when ATTESTATION-NAME is provided " ,
7477 cmd : fmt .Sprintf (`get attestation first-artifact-attestation --trail %s %s` , suite .trailName , suite .defaultKosliArguments ),
75- golden : "Error: required flag(s) \" flow \" not set \n " ,
78+ golden : "Error: --flow is required when using ATTESTATION-NAME \n " ,
7679 },
7780 {
7881 wantError : true ,
79- name : "missing --api-token fails" ,
82+ name : "05 missing --api-token fails" ,
8083 cmd : fmt .Sprintf (`get attestation first-artifact-attestation --flow %s --org orgX` , suite .flowName ),
81- golden : "Error: --api-token is not set\n Usage: kosli get attestation ATTESTATION-NAME [flags]\n " ,
84+ golden : "Error: --api-token is not set\n Usage: kosli get attestation [ ATTESTATION-NAME] [flags]\n " ,
8285 },
8386 {
84- name : "getting an existing trail attestation works" ,
87+ name : "06 getting an existing trail attestation works" ,
8588 cmd : fmt .Sprintf (`get attestation first-trail-attestation --flow %s --trail %s %s` , suite .flowName , suite .trailName , suite .defaultKosliArguments ),
8689 },
8790 {
88- name : "getting an existing trail attestation with --output json works" ,
91+ name : "07 getting an existing trail attestation with --output json works" ,
8992 cmd : fmt .Sprintf (`get attestation first-trail-attestation --flow %s --trail %s --output json %s` , suite .flowName , suite .trailName , suite .defaultKosliArguments ),
9093 goldenJson : []jsonCheck {{"" , "non-empty" }},
9194 },
9295 {
93- name : "getting an existing artifact attestation works" ,
96+ name : "08 getting an existing artifact attestation works" ,
9497 cmd : fmt .Sprintf (`get attestation first-artifact-attestation --flow %s --fingerprint %s %s` , suite .flowName , suite .fingerprint , suite .defaultKosliArguments ),
9598 },
9699 {
97- name : "getting an existing artifact attestation with --output json works" ,
100+ name : "09 getting an existing artifact attestation with --output json works" ,
98101 cmd : fmt .Sprintf (`get attestation first-artifact-attestation --flow %s --fingerprint %s --output json %s` , suite .flowName , suite .fingerprint , suite .defaultKosliArguments ),
99102 goldenJson : []jsonCheck {{"" , "non-empty" }},
100103 },
101104 {
102105 wantError : true ,
103- name : "missing both trail and fingerprint fails" ,
106+ name : "10 missing both trail and fingerprint fails if ATTESTATION-NAME provided " ,
104107 cmd : fmt .Sprintf (`get attestation first-artifact-attestation --flow %s %s` , suite .flowName , suite .defaultKosliArguments ),
105- golden : "Error: at least one of --trail, --fingerprint is required\n " ,
108+ golden : "Error: at least one of --trail, --fingerprint is required when using ATTESTATION-NAME \n " ,
106109 },
107110 {
108111 wantError : true ,
109- name : "providing both trail and fingerprint fails" ,
112+ name : "11 providing both trail and fingerprint fails" ,
110113 cmd : fmt .Sprintf (`get attestation first-artifact-attestation --flow %s --trail %s --fingerprint %s %s` , suite .flowName , suite .trailName , suite .fingerprint , suite .defaultKosliArguments ),
111- golden : "Error: only one of --trail, --fingerprint is allowed\n " ,
114+ golden : "Error: only one of --trail, --fingerprint is allowed when using ATTESTATION-NAME\n " ,
115+ },
116+ {
117+ name : "12 can get an attestation from its id" ,
118+ cmd : fmt .Sprintf (`get attestation --attestation-id %s %s` , suite .attestationId , suite .defaultKosliArguments ),
119+ },
120+ {
121+ wantError : false ,
122+ name : "13 if no attestation found when getting by name, say so" ,
123+ cmd : fmt .Sprintf (`get attestation --attestation-id %s %s` , "non-existent-attestation-id" , suite .defaultKosliArguments ),
124+ golden : "No attestations found.\n " ,
125+ },
126+ {
127+ wantError : false ,
128+ name : "14 if no attestation found when getting by id return empty list in json format" ,
129+ cmd : fmt .Sprintf (`get attestation --attestation-id %s --output json %s` , "non-existent-attestation-id" , suite .defaultKosliArguments ),
130+ goldenJson : []jsonCheck {{"data" , "length:0" }},
131+ },
132+ {
133+ wantError : true ,
134+ name : "15 providing both attestation id and attestation name fails" ,
135+ cmd : fmt .Sprintf (`get attestation %s --attestation-id %s %s` , "first-artifact-attestation" , suite .attestationId , suite .defaultKosliArguments ),
136+ golden : "Error: --attestation-id cannot be used when ATTESTATION-NAME is provided\n " ,
137+ },
138+ {
139+ wantError : true ,
140+ name : "16 providing both attestation id and trail fails" ,
141+ cmd : fmt .Sprintf (`get attestation --attestation-id %s --trail %s %s` , suite .attestationId , suite .trailName , suite .defaultKosliArguments ),
142+ golden : "Error: --flow, --trail, and --fingerprint flags cannot be used with --attestation-id\n " ,
143+ },
144+ {
145+ wantError : true ,
146+ name : "17 providing both attestation id and fingerprint fails" ,
147+ cmd : fmt .Sprintf (`get attestation --attestation-id %s --fingerprint %s %s` , suite .attestationId , suite .fingerprint , suite .defaultKosliArguments ),
148+ golden : "Error: --flow, --trail, and --fingerprint flags cannot be used with --attestation-id\n " ,
149+ },
150+ {
151+ wantError : true ,
152+ name : "18 providing both attestation id and flow fails" ,
153+ cmd : fmt .Sprintf (`get attestation --attestation-id %s --flow %s %s` , suite .attestationId , suite .flowName , suite .defaultKosliArguments ),
154+ golden : "Error: --flow, --trail, and --fingerprint flags cannot be used with --attestation-id\n " ,
155+ },
156+ {
157+ wantError : true ,
158+ name : "19 providing neither attestation id or flow fails" ,
159+ cmd : fmt .Sprintf (`get attestation %s` , suite .defaultKosliArguments ),
160+ golden : "Error: one of ATTESTATION-NAME argument or --attestation-id flag is required\n " ,
112161 },
113162 }
114163
0 commit comments