Skip to content

Commit

Permalink
Add support for optionally only clean-up resources that uptest created
Browse files Browse the repository at this point in the history
Signed-off-by: Sergen Yalçın <[email protected]>
  • Loading branch information
sergenyalcin committed Jan 4, 2024
1 parent 98f446e commit 50e42a1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
22 changes: 12 additions & 10 deletions cmd/uptest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ var (
defaultConditions = e2e.Flag("default-conditions", "Comma separated list of default conditions to wait for a successful test.\n"+
"Conditions could be overridden per resource using \"uptest.upbound.io/conditions\" annotation.").Default("Ready").String()

skipDelete = e2e.Flag("skip-delete", "Skip the delete step of the test.").Default("false").Bool()
testDir = e2e.Flag("test-directory", "Directory where kuttl test case will be generated and executed.").Envar("UPTEST_TEST_DIR").Default(filepath.Join(os.TempDir(), "uptest-e2e")).String()
skipDelete = e2e.Flag("skip-delete", "Skip the delete step of the test.").Default("false").Bool()
testDir = e2e.Flag("test-directory", "Directory where kuttl test case will be generated and executed.").Envar("UPTEST_TEST_DIR").Default(filepath.Join(os.TempDir(), "uptest-e2e")).String()
onlyCleanUptestResources = e2e.Flag("only-clean-uptest-resources", "While deletion step, only clean resources that were created by uptest").Default("false").Bool()
)

var (
Expand Down Expand Up @@ -115,14 +116,15 @@ func e2eTests() {
}
}
o := &config.AutomatedTest{
ManifestPaths: examplePaths,
DataSourcePath: *dataSourcePath,
SetupScriptPath: setupPath,
TeardownScriptPath: teardownPath,
DefaultConditions: strings.Split(*defaultConditions, ","),
DefaultTimeout: *defaultTimeout,
Directory: *testDir,
SkipDelete: *skipDelete,
ManifestPaths: examplePaths,
DataSourcePath: *dataSourcePath,
SetupScriptPath: setupPath,
TeardownScriptPath: teardownPath,
DefaultConditions: strings.Split(*defaultConditions, ","),
DefaultTimeout: *defaultTimeout,
Directory: *testDir,
SkipDelete: *skipDelete,
OnlyCleanUptestResources: *onlyCleanUptestResources,
}

kingpin.FatalIfError(internal.RunTest(o), "cannot run e2e tests successfully")
Expand Down
4 changes: 4 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type AutomatedTest struct {
DefaultConditions []string

SkipDelete bool

OnlyCleanUptestResources bool
}

// Manifest represents a resource loaded from an example resource manifest file.
Expand All @@ -72,6 +74,8 @@ type TestCase struct {
Timeout int
SetupScriptPath string
TeardownScriptPath string

OnlyCleanUptestResources bool
}

// Resource represents a Kubernetes object to be tested and asserted
Expand Down
2 changes: 2 additions & 0 deletions internal/templates/03-assert.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ commands:
- command: ${KUBECTL} wait {{ $resource.KindGroup }}/{{ $resource.Name }} --for=delete --timeout 10s
{{- end }}
{{- end }}
{{- if not .TestCase.OnlyCleanUptestResources }}
- command: ${KUBECTL} wait managed --all --for=delete --timeout 10s
{{- end }}
{{- if .TestCase.TeardownScriptPath }}
- command: {{ .TestCase.TeardownScriptPath }}
{{- end }}
7 changes: 4 additions & 3 deletions internal/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ func (t *tester) executeTests() error {

func (t *tester) prepareConfig() (*config.TestCase, []config.Resource, error) { //nolint:gocyclo // TODO: can we break this?
tc := &config.TestCase{
Timeout: t.options.DefaultTimeout,
SetupScriptPath: t.options.SetupScriptPath,
TeardownScriptPath: t.options.TeardownScriptPath,
Timeout: t.options.DefaultTimeout,
SetupScriptPath: t.options.SetupScriptPath,
TeardownScriptPath: t.options.TeardownScriptPath,
OnlyCleanUptestResources: t.options.OnlyCleanUptestResources,
}
examples := make([]config.Resource, 0, len(t.manifests))

Expand Down

0 comments on commit 50e42a1

Please sign in to comment.