Skip to content

Commit 7730624

Browse files
authored
Tests now work with both restx and fastapi. Added goldenJson. server#3896 (#546)
* Fixed several tests * Works for both fastapi and restx * Fixed begin trail
1 parent 807b72c commit 7730624

20 files changed

Lines changed: 184 additions & 114 deletions

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ logs_integration_test_server:
129129
follow_integration_test_server:
130130
@docker logs cli_kosli_server -f ${CONTAINER} 2>&1
131131

132+
enter_integration_test_server:
133+
@docker exec -it --workdir / cli_kosli_server bash
132134

133135
docker:
134136
@docker build -t kosli-cli .

cmd/kosli/archiveAttestationType_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ func (suite *ArchiveAttestationTypeCommandTestSuite) TestArchiveAttestationTypeC
3636
golden: "Custom attestation type archive-attestation-type was archived\n",
3737
},
3838
{
39-
wantError: true,
40-
name: "archiving non-existing custom attestation type fails",
41-
cmd: fmt.Sprintf(`archive attestation-type non-existing %s`, suite.defaultKosliArguments),
42-
golden: "Error: Custom attestation type 'non-existing' does not exist for org 'docs-cmd-test-user'. \n",
39+
wantError: true,
40+
name: "archiving non-existing custom attestation type fails",
41+
cmd: fmt.Sprintf(`archive attestation-type non-existing %s`, suite.defaultKosliArguments),
42+
goldenRegex: "^Error: Custom attestation type 'non-existing' does not exist for org 'docs-cmd-test-user'",
4343
},
4444
{
4545
wantError: true,

cmd/kosli/attestArtifact_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ func (suite *AttestArtifactCommandTestSuite) TestAttestArtifactCmd() {
8282
golden: "Error: --external-fingerprints have labels that don't have a URL in --external-url\n",
8383
},
8484
{
85-
wantError: true,
86-
name: "fails (from server) when --external-fingerprint has invalid fingerprint",
87-
cmd: fmt.Sprintf("attest artifact testdata/file1 --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name cli --commit HEAD --build-url http://www.example.com --commit-url http://www.example.com --external-url file=https://http://www.example.com --external-fingerprint file=7509e5bda0 %s", suite.defaultKosliArguments),
88-
golden: "Error: Input payload validation failed: map[external_urls.file.fingerprint:'7509e5bda0' does not match '^[a-f0-9]{64}$']\n",
85+
wantError: true,
86+
name: "fails (from server) when --external-fingerprint has invalid fingerprint",
87+
cmd: fmt.Sprintf("attest artifact testdata/file1 --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name cli --commit HEAD --build-url http://www.example.com --commit-url http://www.example.com --external-url file=https://http://www.example.com --external-fingerprint file=7509e5bda0 %s", suite.defaultKosliArguments),
88+
goldenRegex: "Error: Input payload validation failed: .*7509e5bda0",
8989
},
9090
{
9191
name: "can attest with annotations against a trail",

cmd/kosli/beginTrail_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ func (suite *BeginTrailCommandTestSuite) TestBeginTrailCmd() {
3636
golden: "Error: accepts 1 arg(s), received 2\n",
3737
},
3838
{
39-
wantError: true,
40-
name: "fails when name is considered invalid by the server",
41-
cmd: fmt.Sprintf("begin trail foo?$bar --flow %s %s", suite.flowName, suite.defaultKosliArguments),
42-
golden: "Error: Input payload validation failed: map[name:'foo?$bar' does not match '^[a-zA-Z0-9][a-zA-Z0-9\\\\.\\\\-_~]*$']\n",
39+
wantError: true,
40+
name: "fails when name is considered invalid by the server",
41+
cmd: fmt.Sprintf("begin trail foo?$bar --flow %s %s", suite.flowName, suite.defaultKosliArguments),
42+
goldenRegex: "^Error.*foo\\?\\$bar",
4343
},
4444
{
4545
wantError: true,

cmd/kosli/createEnvironment_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@ func (suite *CreateEnvironmentCommandTestSuite) TestCreateEnvironmentCmd() {
6767
golden: "Error: only one of --exclude-scaling, --include-scaling is allowed\n",
6868
},
6969
{
70-
wantError: true,
71-
name: "fails if the type case does not match what the server accepts",
72-
cmd: "create env newEnv1 --type k8s" + suite.defaultKosliArguments,
73-
golden: "Error: Input payload validation failed: map[type:'k8s' is not one of ['K8S', 'ECS', 'S3', 'lambda', 'server', 'docker', 'azure-apps', 'logical']]\n",
70+
wantError: true,
71+
name: "fails if the type case does not match what the server accepts",
72+
cmd: "create env newEnv1 --type k8s" + suite.defaultKosliArguments,
73+
goldenRegex: "^Error: Input payload validation failed: .*k8s",
7474
},
7575
{
76-
wantError: true,
77-
name: "fails if the type is not recognized by the server",
78-
cmd: "create env newEnv1 --type unknown" + suite.defaultKosliArguments,
79-
golden: "Error: Input payload validation failed: map[type:'unknown' is not one of ['K8S', 'ECS', 'S3', 'lambda', 'server', 'docker', 'azure-apps', 'logical']]\n",
76+
wantError: true,
77+
name: "fails if the type is not recognized by the server",
78+
cmd: "create env newEnv1 --type unknown" + suite.defaultKosliArguments,
79+
goldenRegex: "^Error: Input payload validation failed: .*unknown",
8080
},
8181
{
8282
wantError: true,
@@ -97,10 +97,10 @@ func (suite *CreateEnvironmentCommandTestSuite) TestCreateEnvironmentCmd() {
9797
golden: "Error: accepts 1 arg(s), received 2\n",
9898
},
9999
{
100-
wantError: true,
101-
name: "fails when name is considered invalid by the server",
102-
cmd: "create env 'foo bar' --type K8S" + suite.defaultKosliArguments,
103-
golden: "Error: Input payload validation failed: map[name:'foo bar' does not match '^[a-zA-Z0-9][a-zA-Z0-9\\\\.\\\\-_]*$']\n",
100+
wantError: true,
101+
name: "fails when name is considered invalid by the server",
102+
cmd: "create env 'foo bar' --type K8S" + suite.defaultKosliArguments,
103+
goldenRegex: "^Error: Input payload validation failed: .*foo bar",
104104
},
105105
{
106106
wantError: false,

cmd/kosli/createFlow_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ func (suite *CreateFlowCommandTestSuite) TestCreateFlowCmd() {
3333
golden: "Error: accepts 1 arg(s), received 2\n",
3434
},
3535
{
36-
wantError: true,
37-
name: "fails when name is considered invalid by the server",
38-
cmd: "create flow 'foo bar'" + suite.defaultKosliArguments,
39-
golden: "Error: Input payload validation failed: map[name:'foo bar' does not match '^[a-zA-Z0-9][a-zA-Z0-9\\\\.\\\\-_~]*$']\n",
36+
wantError: true,
37+
name: "fails when name is considered invalid by the server",
38+
cmd: "create flow 'foo bar'" + suite.defaultKosliArguments,
39+
goldenRegex: "^Error: .*foo bar",
4040
},
4141
{
4242
name: "can create a flow (by default legacy template is used)",

cmd/kosli/getAttestationType_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ func (suite *GetAttestationTypeCommandTestSuite) SetupTest() {
3535
func (suite *GetAttestationTypeCommandTestSuite) TestGetAttestationTypeCmd() {
3636
tests := []cmdTestCase{
3737
{
38-
wantError: true,
39-
name: "getting a non existing attestation type fails",
40-
cmd: fmt.Sprintf(`get attestation-type foo %s`, suite.defaultKosliArguments),
41-
golden: fmt.Sprintf("Error: Custom attestation type 'foo' does not exist for org '%s'. \n", global.Org),
38+
wantError: true,
39+
name: "getting a non existing attestation type fails",
40+
cmd: fmt.Sprintf(`get attestation-type foo %s`, suite.defaultKosliArguments),
41+
goldenRegex: fmt.Sprintf("^Error: Custom attestation type 'foo' does not exist for org '%s'", global.Org),
4242
},
4343
{
4444
wantError: true,
@@ -74,11 +74,6 @@ func (suite *GetAttestationTypeCommandTestSuite) TestGetAttestationTypeCmd() {
7474
cmd: fmt.Sprintf(`get attestation-type %s@v1 %s`, suite.attestationTypeName, suite.defaultKosliArguments),
7575
goldenFile: "output/get/get-attestation-type-version.txt",
7676
},
77-
{
78-
name: "giving a non-integer version number returns the unversioned attestation type",
79-
cmd: fmt.Sprintf(`get attestation-type %s@vone %s`, suite.attestationTypeName, suite.defaultKosliArguments),
80-
goldenFile: "output/get/get-attestation-type.txt",
81-
},
8277
{
8378
name: "getting an existing attestation type with --output json works",
8479
cmd: fmt.Sprintf(`get attestation-type %s --output json %s`, suite.attestationTypeName, suite.defaultKosliArguments),

cmd/kosli/getAttestation_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ func (suite *GetAttestationCommandTestSuite) TestGetAttestationCmd() {
5757
golden: "No attestations found.\n",
5858
},
5959
{
60-
wantError: false,
61-
name: "if no attestation found return empty list in json format",
62-
cmd: fmt.Sprintf(`get attestation non-existent-attestation --flow %s --trail %s %s --output json`, suite.flowName, suite.trailName, suite.defaultKosliArguments),
63-
golden: "[]\n",
60+
wantError: false,
61+
name: "if no attestation found return empty list in json format",
62+
cmd: fmt.Sprintf(`get attestation non-existent-attestation --flow %s --trail %s %s --output json`, suite.flowName, suite.trailName, suite.defaultKosliArguments),
63+
goldenJson: []jsonCheck{{"", "[]"}},
6464
},
6565
{
6666
wantError: true,
@@ -85,16 +85,18 @@ func (suite *GetAttestationCommandTestSuite) TestGetAttestationCmd() {
8585
cmd: fmt.Sprintf(`get attestation first-trail-attestation --flow %s --trail %s %s`, suite.flowName, suite.trailName, suite.defaultKosliArguments),
8686
},
8787
{
88-
name: "getting an existing trail attestation with --output json works",
89-
cmd: fmt.Sprintf(`get attestation first-trail-attestation --flow %s --trail %s --output json %s`, suite.flowName, suite.trailName, suite.defaultKosliArguments),
88+
name: "getting an existing trail attestation with --output json works",
89+
cmd: fmt.Sprintf(`get attestation first-trail-attestation --flow %s --trail %s --output json %s`, suite.flowName, suite.trailName, suite.defaultKosliArguments),
90+
goldenJson: []jsonCheck{{"", "non-empty"}},
9091
},
9192
{
9293
name: "getting an existing artifact attestation works",
9394
cmd: fmt.Sprintf(`get attestation first-artifact-attestation --flow %s --fingerprint %s %s`, suite.flowName, suite.fingerprint, suite.defaultKosliArguments),
9495
},
9596
{
96-
name: "getting an existing artifact attestation with --output json works",
97-
cmd: fmt.Sprintf(`get attestation first-artifact-attestation --flow %s --fingerprint %s --output json %s`, suite.flowName, suite.fingerprint, suite.defaultKosliArguments),
97+
name: "getting an existing artifact attestation with --output json works",
98+
cmd: fmt.Sprintf(`get attestation first-artifact-attestation --flow %s --fingerprint %s --output json %s`, suite.flowName, suite.fingerprint, suite.defaultKosliArguments),
99+
goldenJson: []jsonCheck{{"", "non-empty"}},
98100
},
99101
{
100102
wantError: true,

cmd/kosli/listApprovals_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ func (suite *ListApprovalsCommandTestSuite) TestListApprovalsCmd() {
7777
golden: "No approvals were found.\n",
7878
},
7979
{
80-
name: "listing approvals on an empty flow with --output json works",
81-
cmd: fmt.Sprintf(`list approvals --flow %s --output json %s`, suite.flowName1, suite.defaultKosliArguments),
82-
golden: "[]\n",
80+
name: "listing approvals on an empty flow with --output json works",
81+
cmd: fmt.Sprintf(`list approvals --flow %s --output json %s`, suite.flowName1, suite.defaultKosliArguments),
82+
goldenJson: []jsonCheck{{"", "[]"}},
8383
},
8484
{
8585
name: "listing approvals on a flow works",

cmd/kosli/listArtifacts_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ func (suite *ListArtifactsCommandTestSuite) TestListArtifactsCmd() {
5252
golden: "Error: required flag(s) \"flow\" not set\n",
5353
},
5454
{
55-
wantError: true,
56-
name: "non-existing flow causes an error",
57-
cmd: fmt.Sprintf(`list artifacts --flow non-existing %s`, suite.defaultKosliArguments),
58-
golden: "Error: Flow named 'non-existing' does not exist for organization 'docs-cmd-test-user'. \n",
55+
wantError: true,
56+
name: "non-existing flow causes an error",
57+
cmd: fmt.Sprintf(`list artifacts --flow non-existing %s`, suite.defaultKosliArguments),
58+
goldenRegex: "^Error: Flow named 'non-existing' does not exist for organization 'docs-cmd-test-user'",
5959
},
6060
// TODO: the correct error is overwritten by the hack flag value check in root.go
6161
{
@@ -76,9 +76,9 @@ func (suite *ListArtifactsCommandTestSuite) TestListArtifactsCmd() {
7676
golden: "No artifacts were found.\n",
7777
},
7878
{
79-
name: "listing artifacts on an empty flow with --output json works",
80-
cmd: fmt.Sprintf(`list artifacts --flow %s --output json %s`, suite.flowName1, suite.defaultKosliArguments),
81-
golden: "[]\n",
79+
name: "listing artifacts on an empty flow with --output json works",
80+
cmd: fmt.Sprintf(`list artifacts --flow %s --output json %s`, suite.flowName1, suite.defaultKosliArguments),
81+
goldenJson: []jsonCheck{{"", "[]"}},
8282
},
8383
{
8484
name: "listing artifacts on a flow works",

0 commit comments

Comments
 (0)