diff options
Diffstat (limited to 'Magefile.go')
| -rw-r--r-- | Magefile.go | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/Magefile.go b/Magefile.go index 00d2be7..33db267 100644 --- a/Magefile.go +++ b/Magefile.go @@ -89,6 +89,20 @@ func TestWithName() error { if testName == "" { testName = "TestEventloop" } + isIntegration, err := isIntegrationTest(testName) + if err != nil { + return err + } + if isIntegration { + mg.SerialDeps(All) + if err := buildWorkloadBinary(); err != nil { + return err + } + fmt.Println("Running integration test", testName, "(requires root)...") + env := goEnv() + forwardEnv(env, "HOME", "GOPATH", "GOMODCACHE", "PATH") + return sudoRunWithEnv(env, "go", "test", "./integrationtests/...", "-run", "^"+testName+"$", "-v", "-failfast", "-count=1") + } return sh.RunWithV(goEnv(), "go", "test", "./...", "-run", "^"+testName+"$", "-v", "-failfast") } @@ -243,9 +257,8 @@ func World() error { // IntegrationTest builds everything and runs integration tests with sudo. func IntegrationTest() error { mg.SerialDeps(All) - fmt.Println("Building ioworkload binary...") - if err := sh.RunV("go", "build", "-o", workloadBinaryName, workloadSourcePath); err != nil { - return fmt.Errorf("build ioworkload: %w", err) + if err := buildWorkloadBinary(); err != nil { + return err } fmt.Println("Running integration tests (requires root)...") env := goEnv() @@ -253,6 +266,14 @@ func IntegrationTest() error { return sudoRunWithEnv(env, "go", "test", "./integrationtests/...", "-v", "-failfast", "-count=1") } +func buildWorkloadBinary() error { + fmt.Println("Building ioworkload binary...") + if err := sh.RunWithV(goEnv(), "go", "build", "-o", workloadBinaryName, workloadSourcePath); err != nil { + return fmt.Errorf("build ioworkload: %w", err) + } + return nil +} + // Prof generates CPU and memory profiling PDFs. func Prof() error { if err := runShellCommand("go tool pprof -pdf ./ior ior.cpuprofile > cpuprofile.pdf"); err != nil { @@ -512,3 +533,16 @@ func sortLinesWithLocale(lines []string) (string, error) { } return string(output), nil } + +func isIntegrationTest(testName string) (bool, error) { + out, err := sh.OutputWith(goEnv(), "go", "test", "./integrationtests/...", "-list", ".") + if err != nil { + return false, fmt.Errorf("list integration tests: %w", err) + } + for _, line := range strings.Split(out, "\n") { + if strings.TrimSpace(line) == testName { + return true, nil + } + } + return false, nil +} |
