diff --git a/README.md b/README.md index 4cc5ec1..902889e 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,9 @@ func TestMain(m *testing.M) { defer suite.TearDown(t) suite.Setup(t) - m.Run() + if !suite.SkipTests { + m.Run() + } } func TestBastion(t *testing.T) { diff --git a/README.yaml b/README.yaml index ed0c3c6..1f3a3be 100644 --- a/README.yaml +++ b/README.yaml @@ -154,7 +154,9 @@ introduction: |- defer suite.TearDown(t) suite.Setup(t) - m.Run() + if !suite.SkipTests { + m.Run() + } } func TestBastion(t *testing.T) { diff --git a/pkg/atmos/aws-component-helper/cli.go b/pkg/atmos/aws-component-helper/cli.go index 1619e05..d20047c 100644 --- a/pkg/atmos/aws-component-helper/cli.go +++ b/pkg/atmos/aws-component-helper/cli.go @@ -14,6 +14,7 @@ func parseCLIArgs(ts *TestSuite) *TestSuite { skipTeardownTestSuite := flag.Bool("skip-teardown", ts.SkipTeardownTestSuite, "skip test suite teardown") skipVendorDependencies := flag.Bool("skip-vendor", ts.SkipVendorDependencies, "skip vendor dependencies") skipVerifyEnabledFlag := flag.Bool("skip-verify-enabled-flag", ts.SkipVerifyEnabledFlag, "skip verify enabled flag") + skipTests := flag.Bool("skip-tests", ts.SkipTests, "skip tests") flag.Parse() @@ -28,6 +29,7 @@ func parseCLIArgs(ts *TestSuite) *TestSuite { ts.SkipTeardownTestSuite = *skipTeardownTestSuite ts.SkipVendorDependencies = *skipVendorDependencies ts.SkipVerifyEnabledFlag = *skipVerifyEnabledFlag + ts.SkipTests = *skipTests return ts } diff --git a/pkg/atmos/aws-component-helper/cli_test.go b/pkg/atmos/aws-component-helper/cli_test.go index e0851fb..ecc3252 100644 --- a/pkg/atmos/aws-component-helper/cli_test.go +++ b/pkg/atmos/aws-component-helper/cli_test.go @@ -30,7 +30,11 @@ func TestParseCLIArgs(t *testing.T) { SkipDeployComponentUnderTest: false, SkipDestroyComponentUnderTest: false, SkipTeardownTestSuite: false, + SkipVendorDependencies: false, SkipVerifyEnabledFlag: false, + SkipTests: false, + ForceNewSuite: false, + Index: -1, }, expected: &TestSuite{ SkipNukeTestAccount: false, @@ -40,11 +44,15 @@ func TestParseCLIArgs(t *testing.T) { SkipDeployComponentUnderTest: false, SkipDestroyComponentUnderTest: false, SkipTeardownTestSuite: false, + SkipVendorDependencies: false, SkipVerifyEnabledFlag: false, + SkipTests: false, + ForceNewSuite: false, + Index: -1, }, }, { - name: "all flags set to true", + name: "all skip flags set to true", args: []string{"prog", "-skip-aws-nuke", "-skip-deploy-deps", @@ -53,7 +61,9 @@ func TestParseCLIArgs(t *testing.T) { "-skip-deploy-cut", "-skip-destroy-cut", "-skip-teardown", + "-skip-vendor", "-skip-verify-enabled-flag", + "-skip-tests", }, initial: &TestSuite{}, expected: &TestSuite{ @@ -64,7 +74,54 @@ func TestParseCLIArgs(t *testing.T) { SkipDeployComponentUnderTest: true, SkipDestroyComponentUnderTest: true, SkipTeardownTestSuite: true, + SkipVendorDependencies: true, SkipVerifyEnabledFlag: true, + SkipTests: true, + ForceNewSuite: false, + Index: -1, + }, + }, + { + name: "force new suite and suite index", + args: []string{"prog", + "-force-new-suite", + "-suite-index=5", + }, + initial: &TestSuite{}, + expected: &TestSuite{ + ForceNewSuite: true, + Index: 5, + }, + }, + { + name: "initial values respected when not overridden", + args: []string{"prog", + "-skip-aws-nuke", + "-skip-deploy-deps", + }, + initial: &TestSuite{ + SkipDestroyDependencies: true, + SkipSetupComponentUnderTest: true, + SkipDeployComponentUnderTest: true, + SkipDestroyComponentUnderTest: true, + SkipTeardownTestSuite: true, + SkipVendorDependencies: true, + SkipVerifyEnabledFlag: true, + SkipTests: true, + }, + expected: &TestSuite{ + SkipNukeTestAccount: true, + SkipDeployDependencies: true, + SkipDestroyDependencies: true, + SkipSetupComponentUnderTest: true, + SkipDeployComponentUnderTest: true, + SkipDestroyComponentUnderTest: true, + SkipTeardownTestSuite: true, + SkipVendorDependencies: true, + SkipVerifyEnabledFlag: true, + SkipTests: true, + ForceNewSuite: false, + Index: -1, }, }, } @@ -111,6 +168,14 @@ func TestSkipDestroyDependencies(t *testing.T) { }, expected: true, }, + { + name: "both flags true", + ts: &TestSuite{ + SkipDestroyDependencies: true, + SkipDestroyComponentUnderTest: true, + }, + expected: true, + }, } for _, tt := range tests { @@ -128,16 +193,38 @@ func TestSkipTeardownTestSuite(t *testing.T) { expected bool }{ { - name: "both flags false", + name: "all flags false", ts: &TestSuite{ - SkipTeardownTestSuite: false, + SkipTeardownTestSuite: false, + SkipDestroyDependencies: false, + SkipDestroyComponentUnderTest: false, }, expected: false, }, { name: "SkipTeardownTestSuite true", ts: &TestSuite{ - SkipTeardownTestSuite: true, + SkipTeardownTestSuite: true, + SkipDestroyDependencies: false, + SkipDestroyComponentUnderTest: false, + }, + expected: true, + }, + { + name: "SkipDestroyDependencies true", + ts: &TestSuite{ + SkipTeardownTestSuite: false, + SkipDestroyDependencies: true, + SkipDestroyComponentUnderTest: false, + }, + expected: true, + }, + { + name: "SkipDestroyComponentUnderTest true", + ts: &TestSuite{ + SkipTeardownTestSuite: false, + SkipDestroyDependencies: false, + SkipDestroyComponentUnderTest: true, }, expected: true, }, @@ -150,3 +237,69 @@ func TestSkipTeardownTestSuite(t *testing.T) { }) } } + +func TestSkipNukeTestAccount(t *testing.T) { + tests := []struct { + name string + ts *TestSuite + expected bool + }{ + { + name: "all flags false", + ts: &TestSuite{ + SkipNukeTestAccount: false, + SkipTeardownTestSuite: false, + SkipDestroyDependencies: false, + SkipDestroyComponentUnderTest: false, + }, + expected: false, + }, + { + name: "SkipNukeTestAccount true", + ts: &TestSuite{ + SkipNukeTestAccount: true, + SkipTeardownTestSuite: false, + SkipDestroyDependencies: false, + SkipDestroyComponentUnderTest: false, + }, + expected: true, + }, + { + name: "SkipTeardownTestSuite true", + ts: &TestSuite{ + SkipNukeTestAccount: false, + SkipTeardownTestSuite: true, + SkipDestroyDependencies: false, + SkipDestroyComponentUnderTest: false, + }, + expected: true, + }, + { + name: "SkipDestroyDependencies true", + ts: &TestSuite{ + SkipNukeTestAccount: false, + SkipTeardownTestSuite: false, + SkipDestroyDependencies: true, + SkipDestroyComponentUnderTest: false, + }, + expected: true, + }, + { + name: "SkipDestroyComponentUnderTest true", + ts: &TestSuite{ + SkipNukeTestAccount: false, + SkipTeardownTestSuite: false, + SkipDestroyDependencies: false, + SkipDestroyComponentUnderTest: true, + }, + expected: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := skipNukeTestAccount(tt.ts) + assert.Equal(t, tt.expected, result) + }) + } +} diff --git a/pkg/atmos/aws-component-helper/test_suite.go b/pkg/atmos/aws-component-helper/test_suite.go index e003fb4..4e60199 100644 --- a/pkg/atmos/aws-component-helper/test_suite.go +++ b/pkg/atmos/aws-component-helper/test_suite.go @@ -24,6 +24,7 @@ type TestSuite struct { SkipDestroyComponentUnderTest bool SkipDestroyDependencies bool SkipTeardownTestSuite bool + SkipTests bool SkipVendorDependencies bool SkipVerifyEnabledFlag bool SkipNukeTestAccount bool diff --git a/test/aws-component-helper/test/basic_test.go b/test/aws-component-helper/test/basic_test.go index 9fed2a0..cd57a28 100644 --- a/test/aws-component-helper/test/basic_test.go +++ b/test/aws-component-helper/test/basic_test.go @@ -40,7 +40,9 @@ func TestMain(m *testing.M) { panic(err) } - m.Run() + if !suite.SkipTests { + m.Run() + } } func TestBasic(t *testing.T) {