Skip to content

Commit 0b8664c

Browse files
test: run integration tests from changes (#1247)
* test: run integration tests from change context Signed-off-by: Darren Murray <[email protected]> * test: remove debug file mapping Signed-off-by: Darren Murray <[email protected]> --------- Signed-off-by: Darren Murray <[email protected]>
1 parent 63f35e3 commit 0b8664c

14 files changed

+342
-13
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ integration: build-cli-cross-platform integration-only ## Build and run integrat
5252
.PHONY: integration-generation
5353
integration-generation: build-cli-cross-platform integration-generation-only ## Build and run integration tests
5454

55+
.PHONY: integration-context-tests
56+
integration-context-tests: install-tools ## Run integration tests with build tags from changed files
57+
scripts/integration_test_ctx.sh
58+
5559
.PHONY: integration-generation-only
5660
integration-generation-only: ## Run integration tests
5761
PATH="$(PWD)/bin:${PATH}" go test -v github.com/lacework/go-sdk/integration -timeout 30m -run "^TestGeneration" -tags="generation"
@@ -70,9 +74,7 @@ integration-only: install-tools ## Run integration tests
7074
container_registry \
7175
query \
7276
policy \
73-
event \
7477
help \
75-
integration \
7678
version \
7779
generation \
7880
compliance \

integration/alert_close_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ func TestAlertCloseReasonInline(t *testing.T) {
8282
})
8383
}
8484

85-
func TestAlertCloseInline(t *testing.T) {
85+
// unstable test disabled as part of GROW-1396
86+
func _TestAlertCloseInline(t *testing.T) {
8687
retry.RunWith(threeTimesWaitOneSecond(), t, func(r *retry.R) {
8788
id, err := popAlert()
8889
if err != nil {

integration/alert_rules_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import (
2828
"github.com/stretchr/testify/assert"
2929
)
3030

31-
func TestAlertRuleRead(t *testing.T) {
31+
// Unstable test disabled as part of GROW-1396
32+
func _TestAlertRuleRead(t *testing.T) {
3233
alertRule, createErr := createAlertRuleWithSlackAlertChannel()
3334
if createErr != nil {
3435
log.Fatal(createErr)

integration/azure_generation_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,9 @@ func TestGenerationAzureNoADEnabled(t *testing.T) {
248248
assert.Equal(t, buildTf, tfResult)
249249
}
250250

251+
// Unstable test disabled as part of GROW-1396
251252
// Test generation with config name customization
252-
func TestGenerationAzureNamedConfig(t *testing.T) {
253+
func _TestGenerationAzureNamedConfig(t *testing.T) {
253254
os.Setenv("LW_NOCACHE", "true")
254255
defer os.Setenv("LW_NOCACHE", "")
255256
var final string
@@ -291,8 +292,9 @@ func TestGenerationAzureNamedConfig(t *testing.T) {
291292
assert.Equal(t, buildTf, tfResult)
292293
}
293294

295+
// Unstable test disabled as part of GROW-1396
294296
// Test generation with activity log customization
295-
func TestGenerationAzureNamedActivityLog(t *testing.T) {
297+
func _TestGenerationAzureNamedActivityLog(t *testing.T) {
296298
os.Setenv("LW_NOCACHE", "true")
297299
defer os.Setenv("LW_NOCACHE", "")
298300
var final string

integration/cloud_account_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build cloudAccount
1+
//go:build cloud_account
22

33
// Author:: Salim Afiune Maya (<[email protected]>)
44
// Copyright:: Copyright 2020, Lacework Inc.

integration/configure_unix_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import (
3030
"github.com/stretchr/testify/assert"
3131
)
3232

33-
func TestConfigureCommand(t *testing.T) {
33+
// Unstable test disabled as part of GROW-1396
34+
func _TestConfigureCommand(t *testing.T) {
3435
os.Setenv("LW_NOCACHE", "true")
3536
defer os.Setenv("LW_NOCACHE", "")
3637

@@ -112,7 +113,8 @@ func TestConfigureCommandForOrgAdmins(t *testing.T) {
112113
`, laceworkTOML, "there is a problem with the generated config")
113114
}
114115

115-
func TestConfigureCommandWithProfileFlag(t *testing.T) {
116+
// Unstable test disabled as part of GROW-1396
117+
func _TestConfigureCommandWithProfileFlag(t *testing.T) {
116118
os.Setenv("LW_NOCACHE", "true")
117119
defer os.Setenv("LW_NOCACHE", "")
118120

integration/container_vulnerability_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ type containerVulnerabilityScan struct {
240240
Status string `json:"status"`
241241
}
242242

243-
func TestContainerVulnerabilityCommandsEndToEnd(t *testing.T) {
243+
// Unstable test disabled as part of GROW-1396
244+
func _TestContainerVulnerabilityCommandsEndToEnd(t *testing.T) {
244245
t.Parallel()
245246
var (
246247
out bytes.Buffer

integration/context/ctx.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
"os"
7+
"strings"
8+
9+
"github.com/BurntSushi/toml"
10+
"github.com/lacework/go-sdk/internal/array"
11+
)
12+
13+
var (
14+
ctx IntegrationCtx
15+
allTags []string
16+
)
17+
18+
func init() {
19+
ex, err := os.Getwd()
20+
if err != nil {
21+
log.Fatal("unable to determine ctx.toml path", err)
22+
}
23+
path := fmt.Sprintf("%s/integration/context/ctx.toml", ex)
24+
log.Print(path)
25+
if _, err := toml.DecodeFile(path, &ctx); err != nil {
26+
log.Fatal("unable to decode integration ctx config")
27+
}
28+
29+
for tag := range ctx {
30+
allTags = append(allTags, tag)
31+
}
32+
33+
}
34+
func main() {
35+
args := os.Args[1:]
36+
if len(args) == 0 {
37+
log.Println("no args provided")
38+
os.Exit(0)
39+
}
40+
41+
testContext := integrationCtx(args)
42+
if len(testContext) == 0 {
43+
log.Println("no matching tags found for changes")
44+
os.Exit(0)
45+
}
46+
47+
tags := array.Unique(testContext)
48+
49+
// if 'all' is selected return all tags
50+
if array.ContainsStr(tags, "all") {
51+
log.Printf("running all integration tests: %s", strings.Join(allTags, ","))
52+
fmt.Print(strings.Join(allTags, " "))
53+
return
54+
}
55+
56+
log.Printf("determined test context tags: %s", strings.Join(tags, ","))
57+
fmt.Print(strings.Join(tags, " "))
58+
}
59+
60+
func integrationCtx(args []string) (buildTags []string) {
61+
log.Print("determining context...")
62+
for _, file := range args {
63+
for tagKey, tag := range ctx {
64+
// handle matching files
65+
if file != "" && array.ContainsStr(tag.Files, file) || array.ContainsStr(tag.Dirs, file) {
66+
log.Println(file)
67+
if !array.ContainsStr(buildTags, tagKey) {
68+
buildTags = append(buildTags, tagKey)
69+
log.Printf("added tag %s", tagKey)
70+
}
71+
continue
72+
}
73+
}
74+
}
75+
return
76+
}
77+
78+
type IntegrationCtx map[string]TestCtx
79+
80+
type TestCtx struct {
81+
Files []string `toml:"files"`
82+
Dirs []string `toml:"dirs"`
83+
}

integration/context/ctx.toml

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
# Integration Test Context Mapping for CLI commands
2+
[account]
3+
files = ["account.go"]
4+
dirs = []
5+
6+
[agent]
7+
files = [
8+
"agent.go",
9+
"agent_aws-install_ec2ic.go",
10+
"agent_aws-install_ec2ssh.go",
11+
"agent_aws-install_ec2ssm.go",
12+
"agent_gcp-install-osl.go",
13+
"agent_install.go",
14+
"agent_list.go",
15+
"awsiam.go",
16+
"flags.go",
17+
]
18+
dirs = ["lwcloud/"]
19+
20+
[alert]
21+
files = [
22+
"alert.go",
23+
"alert_close.go",
24+
"alert_comment.go",
25+
"alert_list.go",
26+
"alert_list_fixable.go",
27+
"alert_rules.go",
28+
"alert_show.go",
29+
"alert_show_details.go",
30+
"alert_show_events.go",
31+
"alert_show_integrations.go",
32+
"alert_show_investigation.go",
33+
"alert_show_related.go",
34+
"alert_show_timeline.go",
35+
]
36+
dirs = []
37+
38+
[alert_rule]
39+
files = ["alert_rules.go"]
40+
dirs = []
41+
42+
[alert_channel]
43+
files = [
44+
"alert_channel.go",
45+
"integration_aws_cloudwatch.go,",
46+
"integration_aws_s3_channel.go",
47+
"integration_cisco_webex.go",
48+
"integration_datadog.go",
49+
"integration_qradar_channel.go",
50+
"integration_service_now_channel.go",
51+
"integration_slack_channel.go",
52+
"integration_splunk.go",
53+
"integration_victorops.go",
54+
"integration_webhook.go",
55+
"integration_pagerduty.go",
56+
"integration_jira.go",
57+
"integration_microsoft_teams.go",
58+
"integration_new_relic_channel.go",
59+
"integration_gcp_pub_sub_channel.go",
60+
"integration_email.go",
61+
]
62+
dirs = []
63+
64+
[alert_profile]
65+
files = ["alert_profiles.go"]
66+
dirs = []
67+
68+
[cloud_account]
69+
files = [
70+
"cloud_account.go",
71+
"integration_gcp.go",
72+
"integration_gcp_pub_sub_audit.go",
73+
"integration_azure.go",
74+
"integration_aws.go",
75+
"integration_aws_govcloud.go"
76+
]
77+
dirs = []
78+
79+
[component]
80+
files = [
81+
"cdk.go",
82+
"component.go",
83+
"component_args.go",
84+
"component_dev.go"
85+
]
86+
dirs = ["cdk/", "lwcomponent/"]
87+
88+
[compliance]
89+
files = [
90+
"compliance.go",
91+
"compliance_aws.go",
92+
"compliance_azure.go",
93+
"compliance_gcp.go",
94+
]
95+
dirs = []
96+
97+
[container_registry]
98+
files = [
99+
"container_registry.go",
100+
"integration_ctr_reg_limits.go",
101+
"integration_ecr.go",
102+
"integration_gar.go",
103+
"integration_gcr.go",
104+
"integration_ghcr.go",
105+
"integration_inline_scanner.go",
106+
"integration_proxy_scanner.go",
107+
]
108+
dirs = []
109+
110+
[query]
111+
files = [
112+
"lql.go",
113+
"lql_create.go",
114+
"lql_delete.go",
115+
"lql_library.go",
116+
"lql_list.go",
117+
"lql_preview.go",
118+
"lql_show.go",
119+
"lql_sources.go",
120+
"lql_update.go",
121+
"lql_validate.go",
122+
"errors_lql.go"
123+
]
124+
dirs = []
125+
126+
[policy]
127+
files = ["content_library.go",
128+
"policy.go",
129+
"policy_create.go",
130+
"policy_delete.go",
131+
"policy_disable.go",
132+
"policy_enable.go",
133+
"policy_exceptions.go",
134+
"policy_library.go",
135+
"policy_update.go",
136+
]
137+
dirs = []
138+
139+
[generation]
140+
files = [
141+
"generate.go",
142+
"generate_aws.go",
143+
"generate_aws_eks_audit.go",
144+
"generate_aws_test.go",
145+
"generate_azure.go",
146+
"generate_cloud_account.go",
147+
"generate_execute.go",
148+
"generate_gcp.go",
149+
"generate_gke.go",
150+
"generate_k8s.go"
151+
]
152+
dirs = ["lwgenerate/"]
153+
154+
[help]
155+
files = ["doc.go"]
156+
dirs = ["integration/test_resources/help/"]
157+
158+
[report_definitions]
159+
files = [
160+
"report_definitions.go",
161+
"report_definitions_create.go",
162+
"report_definitions_diff.go",
163+
"report_definitions_revert.go",
164+
"report_definitions_update.go"
165+
]
166+
dirs = []
167+
168+
[team_member]
169+
files = ["team_members.go"]
170+
dirs = []
171+
172+
[version]
173+
files = ["version.go"]
174+
dirs = []
175+
176+
[vulnerability]
177+
files = [
178+
"vuln_container.go",
179+
"vuln_container_list_assessments.go",
180+
"vuln_container_list_registries.go",
181+
"vuln_container_scan.go",
182+
"vuln_container_show_assessments.go",
183+
"vuln_host.go",
184+
"vuln_host_gen_package_manifest.go",
185+
"vuln_host_list_cves.go",
186+
"vuln_host_list_hosts.go",
187+
"vuln_host_scan_package_manifest.go",
188+
"vuln_host_show_assessment.go",
189+
"vuln_html.go",
190+
"vulnerability.go",
191+
"vulnerability_exception_container.go",
192+
"vulnerability_exception_host.go",
193+
"vulnerabilty_exceptions.go",
194+
"package_manifest.go"
195+
]
196+
dirs = []
197+
198+
# If these files change run all tests
199+
[all]
200+
files = ["cache.go", "cli_state.go", "root.go", "table_render.go", "honeyvent.go", "errors.go", "outputs.go"]
201+
dirs = ["lwtime/", "lwdomain/", "lwconfig/"]

integration/gke_generation_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ func TestGenerationExistingSink(t *testing.T) {
190190
assert.Equal(t, buildTf, tfResult)
191191
}
192192

193-
func TestGenerationGkeAdvancedOptsUseExistingSA(t *testing.T) {
193+
// Unstable test disabled as part of GROW-1396
194+
func _TestGenerationGkeAdvancedOptsUseExistingSA(t *testing.T) {
194195
os.Setenv("LW_NOCACHE", "true")
195196
defer os.Setenv("LW_NOCACHE", "")
196197
var final string

0 commit comments

Comments
 (0)