Skip to content

Commit

Permalink
Merge pull request #23 from sergenyalcin/add-new-cli-opts
Browse files Browse the repository at this point in the history
Add new cli options: `disable-import` and `disable-update`
  • Loading branch information
jeanduplessis authored Aug 30, 2024
2 parents 8a80a6a + d4abb6a commit 8512885
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
4 changes: 4 additions & 0 deletions cmd/uptest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ var (
renderOnly = e2e.Flag("render-only", "Only render test files. Do not run the tests.").Default("false").Bool()
logCollectInterval = e2e.Flag("log-collect-interval", "Specifies the interval duration for collecting logs. "+
"The duration should be provided in a format understood by the tool, such as seconds (s), minutes (m), or hours (h). For example, '30s' for 30 seconds, '5m' for 5 minutes, or '1h' for one hour.").Default("30s").Duration()
skipUpdate = e2e.Flag("skip-update", "Skip the update step of the test.").Default("false").Bool()
skipImport = e2e.Flag("skip-import", "Skip the import step of the test.").Default("false").Bool()
)

func main() {
Expand Down Expand Up @@ -95,6 +97,8 @@ func e2eTests() {
DefaultTimeout: *defaultTimeout,
Directory: *testDir,
SkipDelete: *skipDelete,
SkipUpdate: *skipUpdate,
SkipImport: *skipImport,
OnlyCleanUptestResources: *onlyCleanUptestResources,
RenderOnly: *renderOnly,
LogCollectionInterval: *logCollectInterval,
Expand Down
2 changes: 2 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ type AutomatedTest struct {
DefaultConditions []string

SkipDelete bool
SkipUpdate bool
SkipImport bool

OnlyCleanUptestResources bool

Expand Down
5 changes: 5 additions & 0 deletions internal/templates/03-delete.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ spec:
for:
deletion: {}
{{- end }}
{{- if not .TestCase.OnlyCleanUptestResources }}
- script:
content: |
${KUBECTL} wait managed --all --for=delete --timeout -1s
{{- end }}
{{- if .TestCase.TeardownScriptPath }}
- command:
entrypoint: {{ .TestCase.TeardownScriptPath }}
Expand Down
6 changes: 6 additions & 0 deletions internal/templates/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ spec:
name: example-bucket
for:
deletion: {}
- script:
content: |
${KUBECTL} wait managed --all --for=delete --timeout -1s
`,
},
},
Expand Down Expand Up @@ -435,6 +438,9 @@ spec:
namespace: upbound-system
for:
deletion: {}
- script:
content: |
${KUBECTL} wait managed --all --for=delete --timeout -1s
- command:
entrypoint: /tmp/teardown.sh
`,
Expand Down
30 changes: 23 additions & 7 deletions internal/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,21 @@ func logCollector(done chan bool, ticker *time.Ticker, mutex sync.Locker, resour
return
case <-ticker.C:
mutex.Lock()
log.Printf("crossplane trace logs %s\n", time.Now())
for _, r := range resources {
traceCmd := exec.Command("bash", "-c", fmt.Sprintf(`"${CROSSPLANE_CLI}" beta trace %s %s -o wide`, r.KindGroup, r.Name)) //nolint:gosec // Disabling gosec to allow dynamic shell command execution
// During the setup script is running, the crossplane command
// is failing because of the resource not found error.
// We do not want to show this error to the user because it
// is a noise and temporary one.
// The error output was redirected to a file.
traceCmd := exec.Command("bash", "-c", fmt.Sprintf(`"${CROSSPLANE_CLI}" beta trace %s %s -o wide 2>>/tmp/uptest_crossplane_temp_errors.log`, r.KindGroup, r.Name)) //nolint:gosec // Disabling gosec to allow dynamic shell command execution
output, err := traceCmd.CombinedOutput()
if err != nil {
log.Println("Error executing crossplane:", err)
} else {
log.Println(string(output))
if err == nil {
log.Printf("crossplane trace logs %s\n%s\n", time.Now(), string(output))
}
}
mutex.Unlock()
}
}

}

func (t *tester) prepareConfig() (*config.TestCase, []config.Resource, error) { //nolint:gocyclo // TODO: can we break this?
Expand All @@ -148,6 +149,7 @@ func (t *tester) prepareConfig() (*config.TestCase, []config.Resource, error) {
}
examples := make([]config.Resource, 0, len(t.manifests))

rootFound := false
for _, m := range t.manifests {
obj := m.Object
groupVersionKind := obj.GroupVersionKind()
Expand Down Expand Up @@ -238,12 +240,26 @@ func (t *tester) prepareConfig() (*config.TestCase, []config.Resource, error) {
tc.SkipUpdate = true
}
example.Root = true
rootFound = true
}
}

examples = append(examples, example)
}

if !rootFound {
log.Println("Skipping update step because the root resource does not exist")
tc.SkipUpdate = true
}
if t.options.SkipUpdate {
log.Println("Skipping update step because the skip-delete option is set to true")
tc.SkipUpdate = true
}
if t.options.SkipImport {
log.Println("Skipping import step because the skip-import option is set to true")
tc.SkipImport = true
}

return tc, examples, nil
}

Expand Down

0 comments on commit 8512885

Please sign in to comment.