Skip to content

Commit 1cf2efd

Browse files
author
Sumit Morchhale
committed
integration test added for engines command
1 parent f3315d7 commit 1cf2efd

4 files changed

Lines changed: 194 additions & 2 deletions

File tree

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/Checkmarx/secret-detection v0.0.3-0.20250327150305-31c2c3be9edf
1010
github.com/MakeNowJust/heredoc v1.0.0
1111
github.com/bouk/monkey v1.0.0
12+
github.com/go-yaml/yaml v2.1.0+incompatible
1213
github.com/gofrs/flock v0.12.1
1314
github.com/golang-jwt/jwt/v5 v5.2.2
1415
github.com/gomarkdown/markdown v0.0.0-20241102151059-6bc1ffdc6e8c
@@ -28,7 +29,6 @@ require (
2829
golang.org/x/text v0.22.0
2930
google.golang.org/grpc v1.67.3
3031
google.golang.org/protobuf v1.36.3
31-
gopkg.in/yaml.v2 v2.4.0
3232
gopkg.in/yaml.v3 v3.0.1
3333
gotest.tools v2.2.0+incompatible
3434
)
@@ -286,6 +286,7 @@ require (
286286
gopkg.in/inf.v0 v0.9.1 // indirect
287287
gopkg.in/ini.v1 v1.67.0 // indirect
288288
gopkg.in/warnings.v0 v0.1.2 // indirect
289+
gopkg.in/yaml.v2 v2.4.0 // indirect
289290
helm.sh/helm/v3 v3.17.0 // indirect
290291
k8s.io/api v0.32.0 // indirect
291292
k8s.io/apiextensions-apiserver v0.32.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZ
410410
github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
411411
github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U=
412412
github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
413+
github.com/go-yaml/yaml v2.1.0+incompatible h1:RYi2hDdss1u4YE7GwixGzWwVo47T8UQwnTLB6vQiq+o=
414+
github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0=
413415
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
414416
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
415417
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=

internal/commands/util/printer/printer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package printer
33
import (
44
"encoding/json"
55
"fmt"
6-
"gopkg.in/yaml.v3"
6+
"github.com/go-yaml/yaml"
77
"io"
88
"reflect"
99
"strconv"

test/integration/engines_test.go

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
//go:build integration
2+
3+
package integration
4+
5+
import (
6+
"gotest.tools/assert"
7+
"testing"
8+
)
9+
10+
/*
11+
func TestEnginesApiList_WithOnlyValidApikeyFlag_Success(t *testing.T) {
12+
originals := getOriginalEnvVars()
13+
14+
setEnvVars(map[string]string{
15+
params.AstAPIKeyEnv: invalidAPIKey,
16+
params.AccessKeyIDEnv: invalidClientID,
17+
params.AccessKeySecretEnv: invalidClientSecret,
18+
params.TenantEnv: invalidTenant,
19+
})
20+
21+
defer setEnvVars(originals)
22+
23+
args := []string{
24+
"engines", "api-list",
25+
flag(params.AstAPIKeyFlag), originals[params.AstAPIKeyEnv],
26+
}
27+
28+
err, _ := executeCommand(t, args...)
29+
assert.NilError(t, err)
30+
}
31+
32+
func TestEnginesApiList_WithOnlyValidApikeyEnvVar_Success(t *testing.T) {
33+
originals := getOriginalEnvVars()
34+
35+
setEnvVars(map[string]string{
36+
params.AstAPIKeyEnv: invalidAPIKey,
37+
params.AccessKeyIDEnv: invalidClientID,
38+
params.AccessKeySecretEnv: invalidClientSecret,
39+
params.TenantEnv: invalidTenant,
40+
})
41+
42+
defer setEnvVars(originals)
43+
44+
args := []string{
45+
"engines", "api-list",
46+
}
47+
48+
err, _ := executeCommand(t, args...)
49+
assert.NilError(t, err)
50+
}
51+
52+
func TestEnginesApiList_WithOnlyInvalidApikeyEnvVar_Fail(t *testing.T) {
53+
originals := getOriginalEnvVars()
54+
55+
setEnvVars(map[string]string{
56+
params.AstAPIKeyEnv: invalidAPIKey,
57+
params.AccessKeyIDEnv: invalidClientID,
58+
params.AccessKeySecretEnv: invalidClientSecret,
59+
params.TenantEnv: invalidTenant,
60+
})
61+
62+
defer setEnvVars(originals)
63+
64+
args := []string{
65+
"engines", "api-list",
66+
}
67+
68+
err, _ := executeCommand(t, args...)
69+
assert.NilError(t, err)
70+
assert.Error(t, err, "Error validating scan types: Token decoding error: token is malformed: token contains an invalid number of segments")
71+
}
72+
*/
73+
74+
func TestEnginesApiList_WithoutFlagSuccess(t *testing.T) {
75+
args := []string{
76+
"engines", "api-list",
77+
}
78+
79+
err, _ := executeCommand(t, args...)
80+
assert.NilError(t, err)
81+
}
82+
83+
func TestEnginesApiList_HelpSuccess(t *testing.T) {
84+
args := []string{
85+
"engines",
86+
}
87+
88+
err, _ := executeCommand(t, args...)
89+
assert.NilError(t, err)
90+
}
91+
92+
func TestEnginesApiList_EngineTypeSuccess1(t *testing.T) {
93+
args := []string{
94+
"engines", "list-api", "--engine-name", "",
95+
}
96+
97+
err, _ := executeCommand(t, args...)
98+
assert.NilError(t, err)
99+
}
100+
101+
func TestEnginesApiList_EngineTypeSuccess2(t *testing.T) {
102+
args := []string{
103+
"engines", "list-api", "--engine-name", "SAST",
104+
}
105+
106+
err, _ := executeCommand(t, args...)
107+
assert.NilError(t, err)
108+
}
109+
110+
func TestEnginesApiList_EngineTypeSuccess3(t *testing.T) {
111+
args := []string{
112+
"engines", "list-api", "--engine-name", "SCA",
113+
}
114+
115+
err, _ := executeCommand(t, args...)
116+
assert.NilError(t, err)
117+
}
118+
119+
func TestEnginesApiList_EngineTypeSuccess4(t *testing.T) {
120+
args := []string{
121+
"engines", "list-api", "--engine-name", "Iac",
122+
}
123+
124+
err, _ := executeCommand(t, args...)
125+
assert.NilError(t, err)
126+
}
127+
128+
func TestEnginesApiList_EngineTypeError1(t *testing.T) {
129+
args := []string{
130+
"engines", "list-api", "--engine-name", "xyz",
131+
}
132+
133+
err, _ := executeCommand(t, args...)
134+
assert.NilError(t, err)
135+
}
136+
137+
func TestEnginesApiList_EngineTypeError2(t *testing.T) {
138+
args := []string{
139+
"engines", "list-api", "--engine-name", "",
140+
}
141+
142+
err, _ := executeCommand(t, args...)
143+
assert.NilError(t, err)
144+
}
145+
146+
func TestEnginesApiList_OutputFormatSuccess1(t *testing.T) {
147+
args := []string{
148+
"engines", "list-api", "--output-format", "table", "--engine-name", "Iac",
149+
}
150+
151+
err, _ := executeCommand(t, args...)
152+
assert.NilError(t, err)
153+
}
154+
155+
func TestEnginesApiList_OutputFormatSuccess2(t *testing.T) {
156+
args := []string{
157+
"engines", "list-api", "--output-format", "json", "--engine-name", "Iac",
158+
}
159+
160+
err, _ := executeCommand(t, args...)
161+
assert.NilError(t, err)
162+
}
163+
164+
func TestEnginesApiList_OutputFormatSuccess3(t *testing.T) {
165+
args := []string{
166+
"engines", "list-api", "--output-format", "yaml", "--engine-name", "Iac",
167+
}
168+
169+
err, _ := executeCommand(t, args...)
170+
assert.NilError(t, err)
171+
}
172+
173+
func TestEnginesApiList_OutputFormatError1(t *testing.T) {
174+
args := []string{
175+
"engines", "list-api", "--output-format", "xyz", "--engine-name", "Iac",
176+
}
177+
178+
err, _ := executeCommand(t, args...)
179+
assert.Equal(t, err.Error(), "Invalid format xyz")
180+
}
181+
182+
func TestEnginesApiList_FlagError1(t *testing.T) {
183+
args := []string{
184+
"engines", "list-api", "--engines-name",
185+
}
186+
187+
err, _ := executeCommand(t, args...)
188+
assert.Equal(t, err.Error(), "unknown flag: --engines-name")
189+
}

0 commit comments

Comments
 (0)