Merge pull request #9787 from cli/jtmcg/testscripts-auth
Add acceptance tests for `gh auth` commands
This commit is contained in:
commit
2a2adfed0f
5 changed files with 50 additions and 0 deletions
|
|
@ -63,6 +63,15 @@ func TestAPI(t *testing.T) {
|
|||
testscript.Run(t, testScriptParamsFor(tsEnv, "api"))
|
||||
}
|
||||
|
||||
func TestAuth(t *testing.T) {
|
||||
var tsEnv testScriptEnv
|
||||
if err := tsEnv.fromEnv(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
testscript.Run(t, testScriptParamsFor(tsEnv, "auth"))
|
||||
}
|
||||
|
||||
func TestReleases(t *testing.T) {
|
||||
var tsEnv testScriptEnv
|
||||
if err := tsEnv.fromEnv(); err != nil {
|
||||
|
|
|
|||
25
acceptance/testdata/auth/auth-login-logout.txtar
vendored
Normal file
25
acceptance/testdata/auth/auth-login-logout.txtar
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# We aren't logged in at the moment, but GH_TOKEN will override the
|
||||
# need to login. We are going to clear GH_TOKEN first to ensure no
|
||||
# overrides are happening
|
||||
|
||||
# Copy $GH_TOKEN to a new env var
|
||||
env LOGIN_TOKEN=$GH_TOKEN
|
||||
|
||||
# Remove GH_TOKEN env var so we don't fall back to it
|
||||
env GH_TOKEN=''
|
||||
|
||||
# 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
|
||||
stdout $GH_HOST
|
||||
|
||||
# Logout of the host
|
||||
exec gh auth logout --hostname $GH_HOST
|
||||
stderr 'Logged out of'
|
||||
|
||||
# Check that we are logged out
|
||||
! exec gh auth status --hostname $GH_HOST
|
||||
10
acceptance/testdata/auth/auth-setup-git.txtar
vendored
Normal file
10
acceptance/testdata/auth/auth-setup-git.txtar
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# Check that the credential helper is unset for the host. This command is
|
||||
# expected to fail before gh auth setup-git is run.
|
||||
! exec git config --get credential.https://${GH_HOST}.helper
|
||||
|
||||
# Run the setup-git command
|
||||
exec gh auth setup-git
|
||||
|
||||
# Check that the credential helper is set to gh
|
||||
exec git config --get credential.https://${GH_HOST}.helper
|
||||
stdout '^.*gh auth git-credential$'
|
||||
3
acceptance/testdata/auth/auth-status.txtar
vendored
Normal file
3
acceptance/testdata/auth/auth-status.txtar
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Check the authentication status
|
||||
exec gh auth status --hostname $GH_HOST
|
||||
stdout '✓ Logged in to '
|
||||
3
acceptance/testdata/auth/auth-token.txtar
vendored
Normal file
3
acceptance/testdata/auth/auth-token.txtar
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Check authentication token
|
||||
exec gh auth token --hostname $GH_HOST
|
||||
stdout $GH_TOKEN
|
||||
Loading…
Add table
Add a link
Reference in a new issue