Skip to content

Commit

Permalink
test: add integration test for new options
Browse files Browse the repository at this point in the history
  • Loading branch information
Manan-Bhatia-0 authored and dmurray-lacework committed Aug 2, 2023
1 parent 8ccf866 commit 70cc350
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions integration/gcp_generation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ func TestGenerationPubSubAuditlogOnlyGcp(t *testing.T) {
MsgMenu{cmd.GcpAdvancedOptAuditLog, 0},
MsgRsp{cmd.QuestionUsePubSubAudit, "y"},
MsgRsp{cmd.QuestionGcpUseExistingSink, "n"},
MsgRsp{cmd.QuestionGcpUseExistingPubSubTopic, "n"},
MsgRsp{cmd.QuestionGcpUseExistingPubSubSubscription, "n"},
MsgRsp{cmd.QuestionGcpCustomFilter, ""},
MsgRsp{cmd.QuestionGcpAnotherAdvancedOpt, "n"},
MsgRsp{cmd.QuestionRunTfPlan, "n"},
Expand All @@ -181,6 +183,52 @@ func TestGenerationPubSubAuditlogOnlyGcp(t *testing.T) {
assert.Equal(t, buildTf, tfResult)
}

// Test pub-sub audit log with existing topic and subscription
func TestGenerationPubSubAuditlogExistingTopicAndSubscriptionGcp(t *testing.T) {
os.Setenv("LW_NOCACHE", "true")
defer os.Setenv("LW_NOCACHE", "")
var final string

tfResult := runGcpGenerateTest(t,
func(c *expect.Console) {
expectsCliOutput(t, c, []MsgRspHandler{
MsgRsp{cmd.QuestionGcpEnableConfiguration, "n"},
MsgRsp{cmd.QuestionGcpEnableAuditLog, "y"},
MsgRsp{cmd.QuestionGcpProjectID, projectId},
MsgRsp{cmd.QuestionGcpOrganizationIntegration, "n"},
MsgRsp{cmd.QuestionGcpServiceAccountCredsPath, ""},
MsgRsp{cmd.QuestionGcpConfigureAdvanced, "y"},
MsgMenu{cmd.GcpAdvancedOptAuditLog, 0},
MsgRsp{cmd.QuestionUsePubSubAudit, "y"},
MsgRsp{cmd.QuestionGcpUseExistingSink, "y"},
MsgRsp{cmd.QuestionGcpExistingSinkName, "sink"},
MsgRsp{cmd.QuestionGcpUseExistingPubSubTopic, "y"},
MsgRsp{cmd.QuestionGcpExistingPubSubTopicId, "topicMcTopicFace"},
MsgRsp{cmd.QuestionGcpUseExistingPubSubSubscription, "y"},
MsgRsp{cmd.QuestionGcpExistingPubSubSubscriptionName, "subscriptionMcSubscriptionFace"},
MsgRsp{cmd.QuestionGcpCustomFilter, ""},
MsgRsp{cmd.QuestionGcpAnotherAdvancedOpt, "n"},
MsgRsp{cmd.QuestionRunTfPlan, "n"},
})

final, _ = c.ExpectEOF()
},
"generate",
"cloud-account",
"gcp",
)

assertTerraformSaved(t, final)

buildTf, _ := gcp.NewTerraform(false, true, true,
gcp.WithProjectId(projectId),
gcp.WithExistingLogSinkName("sink"),
gcp.WithExistingPubSubTopicId("topicMcTopicFace"),
gcp.WithExistingPubSubSubscriptionName("subscriptionMcSubscriptionFace"),
).Generate()
assert.Equal(t, buildTf, tfResult)
}

func TestGenerationPubSubAuditlogOrgGcp(t *testing.T) {
os.Setenv("LW_NOCACHE", "true")
defer os.Setenv("LW_NOCACHE", "")
Expand All @@ -199,6 +247,8 @@ func TestGenerationPubSubAuditlogOrgGcp(t *testing.T) {
MsgMenu{cmd.GcpAdvancedOptAuditLog, 0},
MsgRsp{cmd.QuestionUsePubSubAudit, "y"},
MsgRsp{cmd.QuestionGcpUseExistingSink, "n"},
MsgRsp{cmd.QuestionGcpUseExistingPubSubTopic, "n"},
MsgRsp{cmd.QuestionGcpUseExistingPubSubSubscription, "n"},
MsgRsp{cmd.QuestionGcpCustomFilter, ""},
MsgRsp{cmd.QuestionGcpAnotherAdvancedOpt, "n"},
MsgRsp{cmd.QuestionRunTfPlan, "n"},
Expand Down Expand Up @@ -692,6 +742,8 @@ func TestGenerationPubSubUseExistingSA(t *testing.T) {
MsgMenu{cmd.GcpAdvancedOptAuditLog, 0},
MsgRsp{cmd.QuestionUsePubSubAudit, "y"},
MsgRsp{cmd.QuestionGcpUseExistingSink, "n"},
MsgRsp{cmd.QuestionGcpUseExistingPubSubTopic, "n"},
MsgRsp{cmd.QuestionGcpUseExistingPubSubSubscription, "n"},
MsgRsp{cmd.QuestionGcpCustomFilter, ""},
MsgRsp{cmd.QuestionGcpAnotherAdvancedOpt, "y"},
MsgMenu{cmd.GcpAdvancedOptAuditLog, 1},
Expand Down

0 comments on commit 70cc350

Please sign in to comment.