config,etc: rename EnvFetcher, config.Env to OsFetcher, config.Os
This commit is contained in:
parent
18cb9257f9
commit
52b7f015f6
@ -10,7 +10,7 @@ import (
|
||||
|
||||
func TestSSHGetExeAndArgsSsh(t *testing.T) {
|
||||
cfg := config.NewFrom(config.Values{
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"GIT_SSH_COMMAND": "",
|
||||
"GIT_SSH": "",
|
||||
},
|
||||
@ -26,7 +26,7 @@ func TestSSHGetExeAndArgsSsh(t *testing.T) {
|
||||
|
||||
func TestSSHGetExeAndArgsSshCustomPort(t *testing.T) {
|
||||
cfg := config.NewFrom(config.Values{
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"GIT_SSH_COMMAND": "",
|
||||
"GIT_SSH": "",
|
||||
},
|
||||
@ -45,7 +45,7 @@ func TestSSHGetExeAndArgsPlink(t *testing.T) {
|
||||
plink := filepath.Join("Users", "joebloggs", "bin", "plink.exe")
|
||||
|
||||
cfg := config.NewFrom(config.Values{
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"GIT_SSH_COMMAND": "",
|
||||
"GIT_SSH": plink,
|
||||
},
|
||||
@ -63,7 +63,7 @@ func TestSSHGetExeAndArgsPlinkCustomPort(t *testing.T) {
|
||||
plink := filepath.Join("Users", "joebloggs", "bin", "plink")
|
||||
|
||||
cfg := config.NewFrom(config.Values{
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"GIT_SSH_COMMAND": "",
|
||||
"GIT_SSH": plink,
|
||||
},
|
||||
@ -82,7 +82,7 @@ func TestSSHGetExeAndArgsTortoisePlink(t *testing.T) {
|
||||
plink := filepath.Join("Users", "joebloggs", "bin", "tortoiseplink.exe")
|
||||
|
||||
cfg := config.NewFrom(config.Values{
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"GIT_SSH_COMMAND": "",
|
||||
"GIT_SSH": plink,
|
||||
},
|
||||
@ -100,7 +100,7 @@ func TestSSHGetExeAndArgsTortoisePlinkCustomPort(t *testing.T) {
|
||||
plink := filepath.Join("Users", "joebloggs", "bin", "tortoiseplink")
|
||||
|
||||
cfg := config.NewFrom(config.Values{
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"GIT_SSH_COMMAND": "",
|
||||
"GIT_SSH": plink,
|
||||
},
|
||||
@ -117,7 +117,7 @@ func TestSSHGetExeAndArgsTortoisePlinkCustomPort(t *testing.T) {
|
||||
|
||||
func TestSSHGetExeAndArgsSshCommandPrecedence(t *testing.T) {
|
||||
cfg := config.NewFrom(config.Values{
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"GIT_SSH_COMMAND": "sshcmd",
|
||||
"GIT_SSH": "bad",
|
||||
},
|
||||
@ -133,7 +133,7 @@ func TestSSHGetExeAndArgsSshCommandPrecedence(t *testing.T) {
|
||||
|
||||
func TestSSHGetExeAndArgsSshCommandArgs(t *testing.T) {
|
||||
cfg := config.NewFrom(config.Values{
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"GIT_SSH_COMMAND": "sshcmd --args 1",
|
||||
},
|
||||
})
|
||||
@ -148,7 +148,7 @@ func TestSSHGetExeAndArgsSshCommandArgs(t *testing.T) {
|
||||
|
||||
func TestSSHGetExeAndArgsSshCommandCustomPort(t *testing.T) {
|
||||
cfg := config.NewFrom(config.Values{
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"GIT_SSH_COMMAND": "sshcmd",
|
||||
},
|
||||
})
|
||||
@ -166,7 +166,7 @@ func TestSSHGetExeAndArgsPlinkCommand(t *testing.T) {
|
||||
plink := filepath.Join("Users", "joebloggs", "bin", "plink.exe")
|
||||
|
||||
cfg := config.NewFrom(config.Values{
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"GIT_SSH_COMMAND": plink,
|
||||
},
|
||||
})
|
||||
@ -183,7 +183,7 @@ func TestSSHGetExeAndArgsPlinkCommandCustomPort(t *testing.T) {
|
||||
plink := filepath.Join("Users", "joebloggs", "bin", "plink")
|
||||
|
||||
cfg := config.NewFrom(config.Values{
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"GIT_SSH_COMMAND": plink,
|
||||
},
|
||||
})
|
||||
@ -201,7 +201,7 @@ func TestSSHGetExeAndArgsTortoisePlinkCommand(t *testing.T) {
|
||||
plink := filepath.Join("Users", "joebloggs", "bin", "tortoiseplink.exe")
|
||||
|
||||
cfg := config.NewFrom(config.Values{
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"GIT_SSH_COMMAND": plink,
|
||||
},
|
||||
})
|
||||
@ -218,7 +218,7 @@ func TestSSHGetExeAndArgsTortoisePlinkCommandCustomPort(t *testing.T) {
|
||||
plink := filepath.Join("Users", "joebloggs", "bin", "tortoiseplink")
|
||||
|
||||
cfg := config.NewFrom(config.Values{
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"GIT_SSH_COMMAND": plink,
|
||||
},
|
||||
})
|
||||
|
@ -43,7 +43,7 @@ func TestDetermineIncludeExcludePathsReturnsDefaultsWhenAbsent(t *testing.T) {
|
||||
|
||||
func TestCommandEnabledFromEnvironmentVariables(t *testing.T) {
|
||||
cfg := config.NewFrom(config.Values{
|
||||
Env: map[string]string{"GITLFSLOCKSENABLED": "1"},
|
||||
Os: map[string]string{"GITLFSLOCKSENABLED": "1"},
|
||||
})
|
||||
|
||||
assert.True(t, isCommandEnabled(cfg, "locks"))
|
||||
|
@ -47,10 +47,10 @@ type FetchPruneConfig struct {
|
||||
}
|
||||
|
||||
type Configuration struct {
|
||||
// Env provides a `*Environment` used to access to the system's
|
||||
// Os provides a `*Environment` used to access to the system's
|
||||
// environment through os.Getenv. It is the point of entry for all
|
||||
// system environment configuration.
|
||||
Env *Environment
|
||||
Os *Environment
|
||||
|
||||
CurrentRemote string
|
||||
NtlmSession ntlm.ClientSession
|
||||
@ -74,7 +74,7 @@ type Configuration struct {
|
||||
|
||||
func New() *Configuration {
|
||||
c := &Configuration{
|
||||
Env: EnvironmentOf(NewEnvFetcher()),
|
||||
Os: EnvironmentOf(NewOsFetcher()),
|
||||
|
||||
CurrentRemote: defaultRemote,
|
||||
envVars: make(map[string]string),
|
||||
@ -89,9 +89,9 @@ func New() *Configuration {
|
||||
// specifies `Git` and `Env` maps to use as mock values, instead of calling out
|
||||
// to real `.gitconfig`s and the `os.Getenv` function.
|
||||
type Values struct {
|
||||
// Git and Env are the stand-in maps used to provide values for their
|
||||
// Git and Os are the stand-in maps used to provide values for their
|
||||
// respective environments.
|
||||
Git, Env map[string]string
|
||||
Git, Os map[string]string
|
||||
}
|
||||
|
||||
// NewFrom returns a new `*config.Configuration` that reads both its Git
|
||||
@ -101,7 +101,7 @@ type Values struct {
|
||||
// This method should only be used during testing.
|
||||
func NewFrom(v Values) *Configuration {
|
||||
config := &Configuration{
|
||||
Env: EnvironmentOf(mapFetcher(v.Env)),
|
||||
Os: EnvironmentOf(mapFetcher(v.Os)),
|
||||
|
||||
gitConfig: make(map[string]string, 0),
|
||||
envVars: make(map[string]string, 0),
|
||||
@ -121,14 +121,14 @@ func NewFrom(v Values) *Configuration {
|
||||
return config
|
||||
}
|
||||
|
||||
// Getenv is shorthand for `c.Env.Get(key)`.
|
||||
// Getenv is shorthand for `c.Os.Get(key)`.
|
||||
func (c *Configuration) Getenv(key string) string {
|
||||
return c.Env.Get(key)
|
||||
return c.Os.Get(key)
|
||||
}
|
||||
|
||||
// GetenvBool is shorthand for `c.Env.Bool(key, def)`.
|
||||
// GetenvBool is shorthand for `c.Os.Bool(key, def)`.
|
||||
func (c *Configuration) GetenvBool(key string, def bool) bool {
|
||||
return c.Env.Bool(key, def)
|
||||
return c.Os.Bool(key, def)
|
||||
}
|
||||
|
||||
// GitRemoteUrl returns the git clone/push url for a given remote (blank if not found)
|
||||
|
@ -5,11 +5,11 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// EnvFetcher is an implementation of the Fetcher type for communicating with
|
||||
// OsFetcher is an implementation of the Fetcher type for communicating with
|
||||
// the system's environment.
|
||||
//
|
||||
// It is safe to use across multiple goroutines.
|
||||
type EnvFetcher struct {
|
||||
type OsFetcher struct {
|
||||
// vmu guards read/write access to vals
|
||||
vmu sync.Mutex
|
||||
// vals maintains a local cache of the system's enviornment variables
|
||||
@ -17,9 +17,9 @@ type EnvFetcher struct {
|
||||
vals map[string]string
|
||||
}
|
||||
|
||||
// NewEnvFetcher returns a new *EnvFetcher.
|
||||
func NewEnvFetcher() *EnvFetcher {
|
||||
return &EnvFetcher{
|
||||
// NewOsFetcher returns a new *OsFetcher.
|
||||
func NewOsFetcher() *OsFetcher {
|
||||
return &OsFetcher{
|
||||
vals: make(map[string]string),
|
||||
}
|
||||
}
|
||||
@ -33,16 +33,16 @@ func NewEnvFetcher() *EnvFetcher {
|
||||
// the cache or in the system, an empty string will be returned.
|
||||
//
|
||||
// Get is safe to call across multiple goroutines.
|
||||
func (e *EnvFetcher) Get(key string) (val string) {
|
||||
e.vmu.Lock()
|
||||
defer e.vmu.Unlock()
|
||||
func (o *OsFetcher) Get(key string) (val string) {
|
||||
o.vmu.Lock()
|
||||
defer o.vmu.Unlock()
|
||||
|
||||
if i, ok := e.vals[key]; ok {
|
||||
if i, ok := o.vals[key]; ok {
|
||||
return i
|
||||
}
|
||||
|
||||
v := os.Getenv(key)
|
||||
e.vals[key] = v
|
||||
o.vals[key] = v
|
||||
|
||||
return v
|
||||
}
|
@ -102,7 +102,7 @@ func TestCertFromSSLCAInfoEnv(t *testing.T) {
|
||||
tempfile.Close()
|
||||
|
||||
cfg := config.NewFrom(config.Values{
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"GIT_SSL_CAINFO": tempfile.Name(),
|
||||
},
|
||||
})
|
||||
@ -143,7 +143,7 @@ func TestCertFromSSLCAPathEnv(t *testing.T) {
|
||||
assert.Nil(t, err, "Error creating cert file")
|
||||
|
||||
cfg := config.NewFrom(config.Values{
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"GIT_SSL_CAPATH": tempdir,
|
||||
},
|
||||
})
|
||||
@ -161,7 +161,7 @@ func TestCertVerifyDisabledGlobalEnv(t *testing.T) {
|
||||
assert.False(t, isCertVerificationDisabledForHost(cfg, "anyhost.com"))
|
||||
|
||||
cfg = config.NewFrom(config.Values{
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"GIT_SSL_NO_VERIFY": "1",
|
||||
},
|
||||
})
|
||||
|
@ -13,7 +13,7 @@ func TestProxyFromGitConfig(t *testing.T) {
|
||||
Git: map[string]string{
|
||||
"http.proxy": "https://proxy-from-git-config:8080",
|
||||
},
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"HTTPS_PROXY": "https://proxy-from-env:8080",
|
||||
},
|
||||
})
|
||||
@ -34,7 +34,7 @@ func TestHttpProxyFromGitConfig(t *testing.T) {
|
||||
Git: map[string]string{
|
||||
"http.proxy": "http://proxy-from-git-config:8080",
|
||||
},
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"HTTPS_PROXY": "https://proxy-from-env:8080",
|
||||
},
|
||||
})
|
||||
@ -52,7 +52,7 @@ func TestHttpProxyFromGitConfig(t *testing.T) {
|
||||
|
||||
func TestProxyFromEnvironment(t *testing.T) {
|
||||
cfg := config.NewFrom(config.Values{
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"HTTPS_PROXY": "https://proxy-from-env:8080",
|
||||
},
|
||||
})
|
||||
@ -87,7 +87,7 @@ func TestProxyNoProxy(t *testing.T) {
|
||||
Git: map[string]string{
|
||||
"http.proxy": "https://proxy-from-git-config:8080",
|
||||
},
|
||||
Env: map[string]string{
|
||||
Os: map[string]string{
|
||||
"NO_PROXY": "some-host",
|
||||
},
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user