Use real config in auth check tests
This commit is contained in:
parent
dc0f6d55e2
commit
239f983ad4
1 changed files with 21 additions and 21 deletions
|
|
@ -4,53 +4,53 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/cli/cli/v2/internal/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_CheckAuth(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
cfgStubs func(*config.ConfigMock)
|
||||
env map[string]string
|
||||
cfgStubs func(config.Config)
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
name: "no known hosts, no env auth token",
|
||||
cfgStubs: func(c *config.ConfigMock) {},
|
||||
cfgStubs: func(_ config.Config) {},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "no known hosts, env auth token",
|
||||
cfgStubs: func(c *config.ConfigMock) {
|
||||
c.AuthenticationFunc = func() *config.AuthConfig {
|
||||
authCfg := &config.AuthConfig{}
|
||||
authCfg.SetToken("token", "GITHUB_TOKEN")
|
||||
return authCfg
|
||||
}
|
||||
},
|
||||
name: "no known hosts, env auth token",
|
||||
env: map[string]string{"GITHUB_TOKEN": "token"},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "known host",
|
||||
cfgStubs: func(c *config.ConfigMock) {
|
||||
c.Set("github.com", "oauth_token", "token")
|
||||
cfgStubs: func(c config.Config) {
|
||||
_, err := c.Authentication().Login("github.com", "test-user", "test-token", "https", false)
|
||||
require.NoError(t, err)
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "enterprise token",
|
||||
cfgStubs: func(c *config.ConfigMock) {
|
||||
t.Setenv("GH_ENTERPRISE_TOKEN", "token")
|
||||
},
|
||||
name: "enterprise token",
|
||||
env: map[string]string{"GH_ENTERPRISE_TOKEN": "token"},
|
||||
expected: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cfg := config.NewBlankConfig()
|
||||
tt.cfgStubs(cfg)
|
||||
result := CheckAuth(cfg)
|
||||
assert.Equal(t, tt.expected, result)
|
||||
cfg, _ := config.NewIsolatedTestConfig(t)
|
||||
if tt.cfgStubs != nil {
|
||||
tt.cfgStubs(cfg)
|
||||
}
|
||||
|
||||
for k, v := range tt.env {
|
||||
t.Setenv(k, v)
|
||||
}
|
||||
|
||||
require.Equal(t, tt.expected, CheckAuth(cfg))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue