make string var as constant

This commit is contained in:
yw-liu 2020-04-17 00:00:24 +08:00
parent 7912e4c87b
commit 0fc311a8b7
2 changed files with 11 additions and 9 deletions

View File

@ -27,10 +27,12 @@ import (
const ( const (
gitPullMethodEnvKey = "GIT_PULL_METHOD" gitPullMethodEnvKey = "GIT_PULL_METHOD"
gitPullMethodHttps = "https"
gitPullMethodHttp = "http"
) )
var ( var (
supportedGitPullMethods = map[string]bool{"https": true, "http": true} supportedGitPullMethods = map[string]bool{gitPullMethodHttps: true, gitPullMethodHttp: true}
) )
// Git unifies calls to download and unpack the build context. // Git unifies calls to download and unpack the build context.

View File

@ -15,7 +15,7 @@ func TestGetGitPullMethod(t *testing.T) {
{ {
testName: "noEnv", testName: "noEnv",
setEnv: func() (expectedValue string) { setEnv: func() (expectedValue string) {
expectedValue = "https" expectedValue = gitPullMethodHttps
return return
}, },
}, },
@ -23,18 +23,18 @@ func TestGetGitPullMethod(t *testing.T) {
testName: "emptyEnv", testName: "emptyEnv",
setEnv: func() (expectedValue string) { setEnv: func() (expectedValue string) {
_ = os.Setenv(gitPullMethodEnvKey, "") _ = os.Setenv(gitPullMethodEnvKey, "")
expectedValue = "https" expectedValue = gitPullMethodHttps
return return
}, },
}, },
{ {
testName: "httpEnv", testName: "httpEnv",
setEnv: func() (expectedValue string) { setEnv: func() (expectedValue string) {
err := os.Setenv(gitPullMethodEnvKey, "http") err := os.Setenv(gitPullMethodEnvKey, gitPullMethodHttp)
if nil != err { if nil != err {
expectedValue = "https" expectedValue = gitPullMethodHttps
} else { } else {
expectedValue = "http" expectedValue = gitPullMethodHttp
} }
return return
}, },
@ -42,8 +42,8 @@ func TestGetGitPullMethod(t *testing.T) {
{ {
testName: "httpsEnv", testName: "httpsEnv",
setEnv: func() (expectedValue string) { setEnv: func() (expectedValue string) {
_ = os.Setenv(gitPullMethodEnvKey, "https") _ = os.Setenv(gitPullMethodEnvKey, gitPullMethodHttps)
expectedValue = "https" expectedValue = gitPullMethodHttps
return return
}, },
}, },
@ -51,7 +51,7 @@ func TestGetGitPullMethod(t *testing.T) {
testName: "unknownEnv", testName: "unknownEnv",
setEnv: func() (expectedValue string) { setEnv: func() (expectedValue string) {
_ = os.Setenv(gitPullMethodEnvKey, "unknown") _ = os.Setenv(gitPullMethodEnvKey, "unknown")
expectedValue = "https" expectedValue = gitPullMethodHttps
return return
}, },
}, },