Skip to content

Commit

Permalink
allow skipping test runs (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcalhoun authored Nov 26, 2024
1 parent 73e253b commit c751907
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 7 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ introduction: |-
defer suite.TearDown(t)
suite.Setup(t)
m.Run()
if !suite.SkipTests {
m.Run()
}
}
func TestBastion(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/atmos/aws-component-helper/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -28,6 +29,7 @@ func parseCLIArgs(ts *TestSuite) *TestSuite {
ts.SkipTeardownTestSuite = *skipTeardownTestSuite
ts.SkipVendorDependencies = *skipVendorDependencies
ts.SkipVerifyEnabledFlag = *skipVerifyEnabledFlag
ts.SkipTests = *skipTests
return ts
}

Expand Down
161 changes: 157 additions & 4 deletions pkg/atmos/aws-component-helper/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand All @@ -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{
Expand All @@ -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,
},
},
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
},
Expand All @@ -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)
})
}
}
1 change: 1 addition & 0 deletions pkg/atmos/aws-component-helper/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type TestSuite struct {
SkipDestroyComponentUnderTest bool
SkipDestroyDependencies bool
SkipTeardownTestSuite bool
SkipTests bool
SkipVendorDependencies bool
SkipVerifyEnabledFlag bool
SkipNukeTestAccount bool
Expand Down
4 changes: 3 additions & 1 deletion test/aws-component-helper/test/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func TestMain(m *testing.M) {
panic(err)
}

m.Run()
if !suite.SkipTests {
m.Run()
}
}

func TestBasic(t *testing.T) {
Expand Down

0 comments on commit c751907

Please sign in to comment.