Skip to content

Commit d3efde7

Browse files
committed
internal/e2e: tweak how we use secret env vars
Only require GITHUB_TOKEN when a script calls create-github-token. This allows other tests which don't require github auth to be run on their own via `go test -run` without having to set this secret. The failure is now done via t.Fatal instead of panic, and the env var is only passed along for `git push` via the builtin. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I54d7822938cea7d1c1c66b9f7849e60b680e5342 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1171910 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent f9c8d98 commit d3efde7

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

internal/e2e/script_test.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ var (
7676
// This is necessary since we will create a new repository per test,
7777
// and there's no way to easily install the app on each repo via the API.
7878
githubOrg = envOr("GITHUB_ORG", "cue-labs-modules-testing")
79-
// githubToken should have read and write access to repository
80-
// administration and contents within githubOrg,
81-
// to be able to create repositories under the org and git push to them.
82-
githubToken = envMust("GITHUB_TOKEN")
8379
// githubKeep leaves the newly created repo around when set to true.
8480
githubKeep = envOr("GITHUB_KEEP", "false")
8581
)
@@ -92,7 +88,6 @@ func TestScript(t *testing.T) {
9288
env.Setenv("CUE_EXPERIMENT", "modules")
9389
env.Setenv("CUE_REGISTRY", "registry.cue.works")
9490
env.Setenv("CUE_CACHED_GOBIN", os.Getenv("CUE_CACHED_GOBIN"))
95-
env.Setenv("GITHUB_TOKEN", githubToken) // needed for "git push"
9691
return nil
9792
},
9893
Cmds: map[string]func(ts *testscript.TestScript, neg bool, args []string){
@@ -102,6 +97,13 @@ func TestScript(t *testing.T) {
10297
if neg || len(args) > 0 {
10398
ts.Fatalf("usage: create-github-repo")
10499
}
100+
101+
// githubToken should have read and write access to repository
102+
// administration and contents within githubOrg,
103+
// to be able to create repositories under the org and git push to them.
104+
// Not a global, since
105+
githubToken := envMust(t, "GITHUB_TOKEN")
106+
105107
// TODO: name the repo after ts.Name once the API lands
106108
// TODO: add a short random suffix to prevent time collisions
107109
repoName := time.Now().UTC().Format("2006-01-02.15-04-05")
@@ -127,6 +129,7 @@ func TestScript(t *testing.T) {
127129
})
128130

129131
ts.Setenv("MODULE", fmt.Sprintf("github.com/%s/%s", githubOrg, repoName))
132+
ts.Setenv("GITHUB_TOKEN", githubToken) // needed for "git push"
130133
},
131134
// env-fill rewrites its argument files to replace any environment variable
132135
// references with their values, using the same algorithm as cmpenv.
@@ -174,11 +177,12 @@ func envOr(name, fallback string) string {
174177
return fallback
175178
}
176179

177-
func envMust(name string) string {
180+
func envMust(t *testing.T, name string) string {
178181
if s := os.Getenv(name); s != "" {
179182
return s
180183
}
181-
panic(fmt.Sprintf("%s must be set", name))
184+
t.Fatalf("%s must be set", name)
185+
return ""
182186
}
183187

184188
func tsExpand(ts *testscript.TestScript, s string) string {

0 commit comments

Comments
 (0)