this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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í <mvdan@mvdan.cc>
Change-Id: I54d7822938cea7d1c1c66b9f7849e60b680e5342
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1171910
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>

+11 -7
+11 -7
internal/e2e/script_test.go
··· 76 76 // This is necessary since we will create a new repository per test, 77 77 // and there's no way to easily install the app on each repo via the API. 78 78 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") 83 79 // githubKeep leaves the newly created repo around when set to true. 84 80 githubKeep = envOr("GITHUB_KEEP", "false") 85 81 ) ··· 92 88 env.Setenv("CUE_EXPERIMENT", "modules") 93 89 env.Setenv("CUE_REGISTRY", "registry.cue.works") 94 90 env.Setenv("CUE_CACHED_GOBIN", os.Getenv("CUE_CACHED_GOBIN")) 95 - env.Setenv("GITHUB_TOKEN", githubToken) // needed for "git push" 96 91 return nil 97 92 }, 98 93 Cmds: map[string]func(ts *testscript.TestScript, neg bool, args []string){ ··· 102 97 if neg || len(args) > 0 { 103 98 ts.Fatalf("usage: create-github-repo") 104 99 } 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 + 105 107 // TODO: name the repo after ts.Name once the API lands 106 108 // TODO: add a short random suffix to prevent time collisions 107 109 repoName := time.Now().UTC().Format("2006-01-02.15-04-05") ··· 127 129 }) 128 130 129 131 ts.Setenv("MODULE", fmt.Sprintf("github.com/%s/%s", githubOrg, repoName)) 132 + ts.Setenv("GITHUB_TOKEN", githubToken) // needed for "git push" 130 133 }, 131 134 // env-fill rewrites its argument files to replace any environment variable 132 135 // references with their values, using the same algorithm as cmpenv. ··· 174 177 return fallback 175 178 } 176 179 177 - func envMust(name string) string { 180 + func envMust(t *testing.T, name string) string { 178 181 if s := os.Getenv(name); s != "" { 179 182 return s 180 183 } 181 - panic(fmt.Sprintf("%s must be set", name)) 184 + t.Fatalf("%s must be set", name) 185 + return "" 182 186 } 183 187 184 188 func tsExpand(ts *testscript.TestScript, s string) string {