diff --git a/acceptance/README.md b/acceptance/README.md index 1a7f6a93d..a1cd3f216 100644 --- a/acceptance/README.md +++ b/acceptance/README.md @@ -32,6 +32,12 @@ A full example invocation can be found below: GH_ACCEPTANCE_HOST= GH_ACCEPTANCE_ORG= GH_ACCEPTANCE_TOKEN= go test -tags=acceptance ./acceptance ``` +While writing a new test, it can be useful to target that specific script by providing the `GH_ACCEPTANCE_SCRIPT` env var in combination with the `-run` flag, for example: + +``` +GH_ACCEPTANCE_SCRIPT=pr-view.txtar GH_ACCEPTANCE_HOST= GH_ACCEPTANCE_ORG= GH_ACCEPTANCE_TOKEN= go test -tags=acceptance -run ^TestPullRequests$ ./acceptance +``` + #### Code Coverage To get code coverage, `go test` can be invoked with `coverpkg` and `coverprofile` like so: diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index bcc27faca..3f3fb48ec 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -35,10 +35,20 @@ func TestPullRequests(t *testing.T) { testscript.Run(t, testScriptParamsFor(tsEnv, "pr")) } -func testScriptParamsFor(tsEnv testScriptEnv, dir string) testscript.Params { +func testScriptParamsFor(tsEnv testScriptEnv, command string) testscript.Params { + var files []string + if tsEnv.script != "" { + files = []string{path.Join("testdata", command, tsEnv.script)} + } + + var dir string + if len(files) == 0 { + dir = path.Join("testdata", command) + } + return testscript.Params{ - Dir: path.Join("testdata", dir), - Files: []string{}, + Dir: dir, + Files: files, Setup: sharedSetup(tsEnv), Cmds: sharedCmds(tsEnv), RequireExplicitExec: true, @@ -128,6 +138,8 @@ type testScriptEnv struct { org string token string + script string + skipDefer bool preserveWorkDir bool } @@ -164,6 +176,7 @@ func (e *testScriptEnv) fromEnv() error { e.org = envMap["GH_ACCEPTANCE_ORG"] e.token = envMap["GH_ACCEPTANCE_TOKEN"] + e.script = os.Getenv("GH_ACCEPTANCE_SCRIPT") e.preserveWorkDir = os.Getenv("GH_ACCEPTANCE_PRESERVE_WORK_DIR") == "true" e.skipDefer = os.Getenv("GH_ACCEPTANCE_SKIP_DEFER") == "true"