mirror of https://gitlab.com/gitlab-org/cli.git
test: fix issue with environment variables being set
This commit is contained in:
parent
0c57027934
commit
a09c60159e
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"gitlab.com/gitlab-org/cli/api"
|
||||
"gitlab.com/gitlab-org/cli/internal/config"
|
||||
"gitlab.com/gitlab-org/cli/test"
|
||||
)
|
||||
|
||||
func Test_groupGraphQLVariables(t *testing.T) {
|
||||
|
@ -96,7 +97,7 @@ hosts:
|
|||
username: monalisa
|
||||
token: OTOKEN
|
||||
`, "")()
|
||||
t.Setenv("GITLAB_TOKEN", "")
|
||||
test.ClearEnvironmentVariables(t)
|
||||
|
||||
api.SetUserAgent("v1.2.3", "darwin", "arm64")
|
||||
versionString := "glab/v1.2.3 (darwin, arm64)"
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gitlab.com/gitlab-org/cli/test"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
|
@ -16,13 +17,6 @@ func eq(t *testing.T, got interface{}, expected interface{}) {
|
|||
}
|
||||
}
|
||||
|
||||
func clearEnvironmentVariables(t *testing.T) {
|
||||
// prevent using environment variables for test
|
||||
t.Setenv("GITLAB_TOKEN", "")
|
||||
t.Setenv("VISUAL", "")
|
||||
t.Setenv("EDITOR", "")
|
||||
}
|
||||
|
||||
func Test_parseConfig(t *testing.T) {
|
||||
defer StubConfig(`---
|
||||
hosts:
|
||||
|
@ -31,7 +25,7 @@ hosts:
|
|||
token: OTOKEN
|
||||
aliases:
|
||||
`, "")()
|
||||
clearEnvironmentVariables(t)
|
||||
test.ClearEnvironmentVariables(t)
|
||||
|
||||
config, err := ParseConfig("config.yml")
|
||||
eq(t, err, nil)
|
||||
|
@ -53,7 +47,7 @@ hosts:
|
|||
username: monalisa
|
||||
token: OTOKEN
|
||||
`, "")()
|
||||
clearEnvironmentVariables(t)
|
||||
test.ClearEnvironmentVariables(t)
|
||||
|
||||
config, err := ParseConfig("config.yml")
|
||||
eq(t, err, nil)
|
||||
|
@ -73,7 +67,7 @@ hosts:
|
|||
token: OTOKEN
|
||||
`, `
|
||||
`)()
|
||||
clearEnvironmentVariables(t)
|
||||
test.ClearEnvironmentVariables(t)
|
||||
|
||||
config, err := ParseConfig("config.yml")
|
||||
eq(t, err, nil)
|
||||
|
@ -86,6 +80,8 @@ hosts:
|
|||
}
|
||||
|
||||
func Test_parseConfig_Local(t *testing.T) {
|
||||
test.ClearEnvironmentVariables(t)
|
||||
|
||||
defer StubConfig(`---
|
||||
git_protocol: ssh
|
||||
editor: vim
|
||||
|
@ -105,6 +101,8 @@ local:
|
|||
}
|
||||
|
||||
func Test_Get_configReadSequence(t *testing.T) {
|
||||
test.ClearEnvironmentVariables(t)
|
||||
|
||||
defer StubConfig(`---
|
||||
git_protocol: ssh
|
||||
editor: vim
|
||||
|
|
|
@ -2,6 +2,7 @@ package config
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
|
@ -93,7 +94,7 @@ func Test_defaultConfig(t *testing.T) {
|
|||
|
||||
editor, err := cfg.Get("", "editor")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "", editor)
|
||||
assert.Equal(t, os.Getenv("EDITOR"), editor)
|
||||
|
||||
aliases, err := cfg.Aliases()
|
||||
assert.Nil(t, err)
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
func Test_HelperFunctions(t *testing.T) {
|
||||
// Base ios object that is modifiede as required
|
||||
// Base ios object that is modified as required
|
||||
ios := &IOStreams{
|
||||
In: os.Stdin,
|
||||
StdOut: NewColorable(os.Stdout),
|
||||
|
|
|
@ -106,6 +106,15 @@ func ExpectLines(t T, output string, lines ...string) {
|
|||
}
|
||||
}
|
||||
|
||||
func ClearEnvironmentVariables(t *testing.T) {
|
||||
// prevent using environment variables for test
|
||||
t.Setenv("GITLAB_TOKEN", "")
|
||||
t.Setenv("VISUAL", "")
|
||||
t.Setenv("EDITOR", "")
|
||||
t.Setenv("GITLAB_ACCESS_TOKEN", "")
|
||||
t.Setenv("OAUTH_TOKEN", "")
|
||||
}
|
||||
|
||||
func GetHostOrSkip(t testing.TB) string {
|
||||
t.Helper()
|
||||
glTestHost := os.Getenv("GITLAB_TEST_HOST")
|
||||
|
|
Loading…
Reference in New Issue