test: fix assertion order, clear token in keyring test

This commit is contained in:
Marek Vospěl 2023-04-12 20:24:02 +02:00
parent f0a7862f85
commit c46ec24b53
No known key found for this signature in database
GPG Key ID: 654D7FAA1531BC24
2 changed files with 10 additions and 8 deletions

View File

@ -41,7 +41,7 @@ $ glab auth login --hostname salsa.debian.org
-h, --hostname string The hostname of the GitLab instance to authenticate with
--stdin Read token from standard input
-t, --token string Your GitLab access token
--use-keyring Store token in your operating system keyring
--use-keyring Store token in your operating system's keyring
```
## Options inherited from parent commands

View File

@ -6,6 +6,7 @@ import (
"github.com/MakeNowJust/heredoc"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zalando/go-keyring"
)
@ -111,19 +112,20 @@ host: gitlab.com
func Test_getFromKeyring(t *testing.T) {
c := NewBlankConfig()
err := c.Set("gitlab.com", "api_host", "gitlab.com")
assert.NoError(t, err)
// Ensure host exists and its token is empty
err := c.Set("gitlab.com", "token", "")
require.NoError(t, err)
keyring.MockInit()
token, err := c.Get("gitlab.com", "token")
assert.Nil(t, err)
assert.Equal(t, token, "")
assert.NoError(t, err)
assert.Equal(t, "", token)
err = keyring.Set("glab:gitlab.com", "", "glpat-1234")
assert.NoError(t, err)
require.NoError(t, err)
token, err = c.Get("gitlab.com", "token")
assert.Nil(t, err)
assert.Equal(t, token, "glpat-1234")
assert.NoError(t, err)
assert.Equal(t, "glpat-1234", token)
}