@@ -22,6 +22,7 @@ type AssertApprovalCommandTestSuite struct {
2222
2323type assertApprovalTestConfig struct {
2424 createApproval bool
25+ isRequest bool
2526}
2627
2728func (suite * AssertApprovalCommandTestSuite ) SetupTest () {
@@ -49,60 +50,83 @@ func (suite *AssertApprovalCommandTestSuite) TestAssertApprovalCmd() {
4950 tests := []cmdTestCase {
5051 {
5152 wantError : true ,
52- name : "missing --org fails" ,
53+ name : "1 missing --org fails" ,
5354 cmd : fmt .Sprintf (`assert approval --fingerprint 8e568bd886069f1290def0caabc1e97ce0e7b80c105e611258b57d76fcef234c --flow %s --api-token secret` , suite .flowName ),
5455 golden : "Error: --org is not set\n Usage: kosli assert approval [IMAGE-NAME | FILE-PATH | DIR-PATH] [flags]\n " ,
5556 },
5657 {
5758 wantError : true ,
58- name : "asserting approval for a non existing artifact fails" ,
59+ name : "2 asserting approval for a non existing artifact fails" ,
5960 cmd : fmt .Sprintf (`assert approval --fingerprint 8e568bd886069f1290def0caabc1e97ce0e7b80c105e611258b57d76fcef234c --flow %s %s` , suite .flowName , suite .defaultKosliArguments ),
6061 golden : "Error: Artifact with fingerprint '8e568bd886069f1290def0caabc1e97ce0e7b80c105e611258b57d76fcef234c' does not exist in flow 'assert-approval' belonging to organization 'docs-cmd-test-user'\n " ,
6162 },
6263 {
6364 wantError : true ,
64- name : "asserting an existing artifact that does not have an approval (using --fingerprint) works and exits with non-zero code" ,
65+ name : "3 asserting an existing artifact that does not have an approval (using --fingerprint) works and exits with non-zero code" ,
6566 cmd : fmt .Sprintf (`assert approval --fingerprint %s --flow %s %s` , suite .fingerprint , suite .flowName , suite .defaultKosliArguments ),
6667 golden : "Error: artifact with fingerprint fcf33337634c2577a5d86fd7ecb0a25a7c1bb5d89c14fd236f546a5759252c02 has no approvals created\n " ,
6768 },
6869 {
6970 wantError : true ,
70- name : "asserting approval of an existing artifact that does not have an approval (using --artifact-type) works and exits with non-zero code" ,
71+ name : "4 asserting approval of an existing artifact that does not have an approval (using --artifact-type) works and exits with non-zero code" ,
7172 cmd : fmt .Sprintf (`assert approval %s --artifact-type file --flow %s %s` , suite .artifactPath , suite .flowName , suite .defaultKosliArguments ),
7273 golden : "Error: artifact with fingerprint fcf33337634c2577a5d86fd7ecb0a25a7c1bb5d89c14fd236f546a5759252c02 has no approvals created\n " ,
7374 },
7475 {
75- name : "asserting approval of an existing artifact that has an approval (using --artifact-type) works and exits with zero code" ,
76+ name : "5 asserting approval of an existing artifact that has an approval (using --artifact-type) works and exits with zero code" ,
7677 cmd : fmt .Sprintf (`assert approval %s --artifact-type file --flow %s %s` , suite .artifactPath , suite .flowName , suite .defaultKosliArguments ),
7778 golden : "artifact with fingerprint fcf33337634c2577a5d86fd7ecb0a25a7c1bb5d89c14fd236f546a5759252c02 is approved (approval no. [1])\n " ,
7879 additionalConfig : assertApprovalTestConfig {
7980 createApproval : true ,
81+ isRequest : false ,
8082 },
8183 },
84+ //The approval created in test 5 is valid for this test also
85+ {
86+ name : "6 asserting approval of an existing artifact that has an approval (using --fingerprint) works and exits with zero code" ,
87+ cmd : fmt .Sprintf (`assert approval --fingerprint %s --flow %s %s` , suite .fingerprint , suite .flowName , suite .defaultKosliArguments ),
88+ golden : "artifact with fingerprint fcf33337634c2577a5d86fd7ecb0a25a7c1bb5d89c14fd236f546a5759252c02 is approved (approval no. [1])\n " ,
89+ },
8290 {
8391 wantError : true ,
84- name : "not providing --fingerprint nor --artifact-type fails" ,
92+ name : "7 not providing --fingerprint nor --artifact-type fails" ,
8593 cmd : fmt .Sprintf (`assert approval --flow %s %s` , suite .flowName , suite .defaultKosliArguments ),
8694 golden : "Error: docker image name or file/dir path is required when --fingerprint is not provided\n Usage: kosli assert approval [IMAGE-NAME | FILE-PATH | DIR-PATH] [flags]\n " ,
8795 },
88- // TODO: this test case does not pass as the validation does not check for it
89- // {
90- // wantError: true,
91- // name: "providing both --fingerprint and --artifact-type fails",
92- // cmd: fmt.Sprintf(`assert approval --artifact-type file --fingerprint %s --flow %s %s`, suite.fingerprint, suite.flowName, suite.defaultKosliArguments),
93- // golden: "COMPLIANT\n",
94- // },
9596 {
9697 wantError : true ,
97- name : "missing --flow fails" ,
98+ name : "8 providing both --fingerprint and --artifact-type fails" ,
99+ cmd : fmt .Sprintf (`assert approval --artifact-type file --fingerprint %s --flow %s %s` , suite .fingerprint , suite .flowName , suite .defaultKosliArguments ),
100+ golden : "Error: only one of --fingerprint, --artifact-type is allowed\n " ,
101+ },
102+ {
103+ wantError : true ,
104+ name : "9 missing --flow fails" ,
98105 cmd : fmt .Sprintf (`assert approval --fingerprint %s %s` , suite .fingerprint , suite .defaultKosliArguments ),
99106 golden : "Error: required flag(s) \" flow\" not set\n " ,
100107 },
108+ {
109+ wantError : true ,
110+ name : "10 asserting approval of an unapproved existing artifact (using --artifact-type) works and exits with non-zero code" ,
111+ cmd : fmt .Sprintf (`assert approval %s --artifact-type file --flow %s %s` , suite .artifactPath , suite .flowName , suite .defaultKosliArguments ),
112+ golden : "Error: artifact with fingerprint fcf33337634c2577a5d86fd7ecb0a25a7c1bb5d89c14fd236f546a5759252c02 is not approved\n " ,
113+ additionalConfig : assertApprovalTestConfig {
114+ createApproval : true ,
115+ isRequest : true ,
116+ },
117+ },
118+ // The approval request created in test 9 is valid here too
119+ {
120+ wantError : true ,
121+ name : "11 asserting approval of an unapproved existing artifact (using --fingerprint) works and exits with non-zero code" ,
122+ cmd : fmt .Sprintf (`assert approval --fingerprint %s --flow %s %s` , suite .fingerprint , suite .flowName , suite .defaultKosliArguments ),
123+ golden : "Error: artifact with fingerprint fcf33337634c2577a5d86fd7ecb0a25a7c1bb5d89c14fd236f546a5759252c02 is not approved\n " ,
124+ },
101125 }
102126
103127 for _ , t := range tests {
104128 if t .additionalConfig != nil && t .additionalConfig .(assertApprovalTestConfig ).createApproval {
105- CreateApproval (suite .flowName , suite .fingerprint , suite .Suite .T ())
129+ CreateApproval (suite .flowName , suite .fingerprint , t . additionalConfig .( assertApprovalTestConfig ). isRequest , suite .Suite .T ())
106130 }
107131 runTestCmd (suite .Suite .T (), []cmdTestCase {t })
108132 }
0 commit comments