Clean up auth-login-logout acceptance test with native functionality
The previous commit introduced two new functions, setEnvVar and deleteEnvVar that are duplicative of functionality native to testscripts. This commit switches to the native functionality and removes the duplicative functions introduced in the previous commit. Additionally, it removes the `--token` flag that was added to `gh auth login`
This commit is contained in:
parent
52daa9cf7d
commit
aaf4c4e4e3
3 changed files with 11 additions and 38 deletions
|
|
@ -240,30 +240,6 @@ func sharedCmds(tsEnv testScriptEnv) map[string]func(ts *testscript.TestScript,
|
|||
|
||||
ts.Check(os.WriteFile(src, data, mode))
|
||||
},
|
||||
// perhaps these need to be extracted to different files, soon?
|
||||
// I'm prompted to ask because "deleteEnvVar" could just be
|
||||
// syntactic sugar for setEnvVar with an empty value. Can't do that
|
||||
// with the current implementation
|
||||
"deleteEnvVar": func(ts *testscript.TestScript, neg bool, args []string) {
|
||||
if neg {
|
||||
ts.Fatalf("unsupported: ! deleteEnvVar")
|
||||
}
|
||||
if len(args) != 1 {
|
||||
ts.Fatalf("usage: deleteEnvVar name")
|
||||
}
|
||||
|
||||
ts.Setenv(args[0], "")
|
||||
},
|
||||
"setEnvVar": func(ts *testscript.TestScript, neg bool, args []string) {
|
||||
if neg {
|
||||
ts.Fatalf("unsupported: ! setEnvVar")
|
||||
}
|
||||
if len(args) != 2 {
|
||||
ts.Fatalf("usage: setEnvVar name value")
|
||||
}
|
||||
|
||||
ts.Setenv(args[0], args[1])
|
||||
},
|
||||
"stdout2env": func(ts *testscript.TestScript, neg bool, args []string) {
|
||||
if neg {
|
||||
ts.Fatalf("unsupported: ! stdout2env")
|
||||
|
|
|
|||
10
acceptance/testdata/auth/auth-login-logout.txtar
vendored
10
acceptance/testdata/auth/auth-login-logout.txtar
vendored
|
|
@ -3,19 +3,21 @@
|
|||
# overrides are happening
|
||||
|
||||
# Copy $GH_TOKEN to a new env var
|
||||
setEnvVar LOGIN_TOKEN $GH_TOKEN
|
||||
env LOGIN_TOKEN=$GH_TOKEN
|
||||
exec echo $LOGIN_TOKEN
|
||||
stdout $GH_TOKEN
|
||||
|
||||
# Remove GH_TOKEN env var so we don't fall back to it
|
||||
deleteEnvVar GH_TOKEN
|
||||
env GH_TOKEN=''
|
||||
|
||||
# Ensure the token was deleted
|
||||
exec echo $GH_TOKEN
|
||||
! stdout '.'
|
||||
|
||||
# Login to the host
|
||||
exec gh auth login --hostname=$GH_HOST --with-token --token=$LOGIN_TOKEN --insecure-storage
|
||||
# Login to the host by feeding the token to stdin
|
||||
exec echo $LOGIN_TOKEN
|
||||
stdin stdout
|
||||
exec gh auth login --hostname=$GH_HOST --with-token --insecure-storage
|
||||
|
||||
# Check that we are logged in
|
||||
exec gh auth status --hostname $GH_HOST
|
||||
|
|
|
|||
|
|
@ -104,18 +104,14 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm
|
|||
}
|
||||
|
||||
if tokenStdin {
|
||||
if opts.Token == "" {
|
||||
defer opts.IO.In.Close()
|
||||
token, err := io.ReadAll(opts.IO.In)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read token from standard input: %w", err)
|
||||
}
|
||||
opts.Token = strings.TrimSpace(string(token))
|
||||
defer opts.IO.In.Close()
|
||||
token, err := io.ReadAll(opts.IO.In)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read token from standard input: %w", err)
|
||||
}
|
||||
opts.Token = strings.TrimSpace(string(token))
|
||||
}
|
||||
|
||||
// I think this is dead code because the token will always be set if we make it past
|
||||
// the conditional above (lines 106-115)
|
||||
if opts.IO.CanPrompt() && opts.Token == "" {
|
||||
opts.Interactive = true
|
||||
}
|
||||
|
|
@ -143,7 +139,6 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm
|
|||
cmd.Flags().StringSliceVarP(&opts.Scopes, "scopes", "s", nil, "Additional authentication scopes to request")
|
||||
cmd.Flags().BoolVar(&tokenStdin, "with-token", false, "Read token from standard input")
|
||||
cmd.Flags().BoolVarP(&opts.Web, "web", "w", false, "Open a browser to authenticate")
|
||||
cmd.Flags().StringVarP(&opts.Token, "token", "t", "", "Authenticate using a personal access token")
|
||||
cmdutil.StringEnumFlag(cmd, &opts.GitProtocol, "git-protocol", "p", "", []string{"ssh", "https"}, "The protocol to use for git operations on this host")
|
||||
|
||||
// secure storage became the default on 2023/4/04; this flag is left as a no-op for backwards compatibility
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue