Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PengyuanZhao committed Dec 6, 2024
1 parent e9ce012 commit 0f95096
Showing 1 changed file with 44 additions and 23 deletions.
67 changes: 44 additions & 23 deletions integration/azure_generation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import (
)

const (
azurePath = "/lacework/azure/"
azurePath = "/lacework/azure/"
mockSubscriptionID = "111aaa1a-a1a1-11aa-a111-1aaaa1a11a11"
)

func expectAzureString(c *expect.Console, str string, runError *error) {
Expand Down Expand Up @@ -69,7 +70,8 @@ func TestGenerationAzureSimple(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "y"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "n"},
MsgRsp{cmd.QuestionRunTfPlan, "n"},
})
Expand Down Expand Up @@ -111,7 +113,8 @@ func TestGenerationAzureCustomizedOutputLocation(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "y"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "y"},
MsgMenu{cmd.AzureAdvancedOptDone, 5},
MsgRsp{cmd.QuestionAzureCustomizeOutputLocation, dir},
Expand Down Expand Up @@ -151,7 +154,8 @@ func TestGenerationAzureConfigOnly(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "n"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "n"},
MsgRsp{cmd.QuestionRunTfPlan, "n"},
})
Expand Down Expand Up @@ -186,7 +190,8 @@ func TestGenerationAzureActivityLogOnly(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "y"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "n"},
MsgRsp{cmd.QuestionRunTfPlan, "n"},
})
Expand Down Expand Up @@ -224,7 +229,8 @@ func TestGenerationAzureNoADEnabled(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "y"},
MsgRsp{cmd.QuestionEnableAdIntegration, "n"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "y"},
MsgMenu{cmd.AzureAdvancedOptLocation, 2},
MsgRsp{cmd.QuestionADApplicationPass, pass},
Expand Down Expand Up @@ -270,7 +276,8 @@ func _TestGenerationAzureNamedConfig(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "n"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "y"},

MsgMenu{cmd.AzureAdvancedOptDone, 0},
Expand Down Expand Up @@ -315,7 +322,8 @@ func _TestGenerationAzureNamedActivityLog(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "y"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "y"},

MsgMenu{cmd.AzureAdvancedOptDone, 0},
Expand Down Expand Up @@ -357,7 +365,8 @@ func TestGenerationAzureAdvancedOptsDone(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "y"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "y"},

MsgMenu{cmd.AzureAdvancedOptDone, 6},
Expand Down Expand Up @@ -406,7 +415,8 @@ func TestGenerationAzureWithExistingTerraform(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "y"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "y"},
MsgMenu{cmd.AzureAdvancedOptDone, 5},
MsgRsp{cmd.QuestionAzureCustomizeOutputLocation, dir},
Expand Down Expand Up @@ -446,7 +456,8 @@ func TestGenerationAzureConfigAllSubs(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "n"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "y"},
MsgMenu{cmd.AzureAdvancedOptDone, 1},
MsgRsp{cmd.QuestionEnableAllSubscriptions, "y"},
Expand Down Expand Up @@ -488,7 +499,8 @@ func TestGenerationAzureConfigMgmntGroup(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "n"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "y"},

MsgMenu{cmd.AzureAdvancedOptDone, 2},
Expand Down Expand Up @@ -533,7 +545,8 @@ func TestGenerationAzureConfigSubs(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "n"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "y"},

MsgMenu{cmd.AzureAdvancedOptDone, 1},
Expand Down Expand Up @@ -578,7 +591,8 @@ func TestGenerationAzureActivityLogSubs(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "y"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "y"},

MsgMenu{cmd.AzureAdvancedOptDone, 1},
Expand Down Expand Up @@ -624,7 +638,8 @@ func TestGenerationAzureActivityLogStorageAccount(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "y"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "y"},

MsgMenu{cmd.AzureAdvancedOptDone, 3},
Expand Down Expand Up @@ -672,7 +687,8 @@ func TestGenerationAzureActivityLogAllSubs(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "y"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "y"},

MsgMenu{cmd.AzureAdvancedOptDone, 1},
Expand Down Expand Up @@ -716,7 +732,8 @@ func TestGenerationAzureActivityLogLocation(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "y"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "y"},

MsgMenu{cmd.AzureAdvancedOptDone, 2},
Expand Down Expand Up @@ -763,7 +780,8 @@ func TestGenerationAzureOverwrite(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "y"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "n"},
MsgRsp{cmd.QuestionRunTfPlan, "n"},
})
Expand All @@ -783,7 +801,8 @@ func TestGenerationAzureOverwrite(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "y"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "n"},
MsgRsp{"already exists, overwrite?", "n"},
MsgRsp{cmd.QuestionRunTfPlan, "n"},
Expand Down Expand Up @@ -820,7 +839,8 @@ func TestGenerationAzureOverwriteOutput(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "y"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "n"},
MsgRsp{cmd.QuestionRunTfPlan, "n"},
})
Expand All @@ -842,7 +862,8 @@ func TestGenerationAzureOverwriteOutput(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "y"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "n"},
MsgRsp{"already exists, overwrite?", "n"},
MsgRsp{cmd.QuestionRunTfPlan, "n"},
Expand Down Expand Up @@ -873,7 +894,8 @@ func TestGenerationAzureLaceworkProfile(t *testing.T) {
MsgRsp{cmd.QuestionEnableActivityLog, "y"},
MsgRsp{cmd.QuestionEnableAdIntegration, "y"},
MsgRsp{cmd.QuestionEnableEntraIdActivityLog, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "n"},
MsgRsp{cmd.QuestionAddAzureSubscriptionID, "y"},
MsgRsp{cmd.QuestionAzureSubscriptionID, mockSubscriptionID},
MsgRsp{cmd.QuestionAzureConfigAdvanced, "n"},
MsgRsp{cmd.QuestionRunTfPlan, "n"},
})
Expand All @@ -900,7 +922,6 @@ func TestGenerationAzureWithSubscriptionID(t *testing.T) {
defer os.Setenv("LW_NOCACHE", "")
var final string
var runError error
mockSubscriptionID := "111aaa1a-a1a1-11aa-a111-1aaaa1a11a11"

// Run CLI
tfResult := runGenerateAzureTest(t,
Expand Down

0 comments on commit 0f95096

Please sign in to comment.