modify code format and unit-test

This commit is contained in:
yw-liu 2020-04-16 23:44:37 +08:00
parent 4f8d074e00
commit d8b8e811dd
2 changed files with 41 additions and 17 deletions

View File

@ -30,7 +30,7 @@ const (
)
var (
supportedGitPullMethods = map[string]bool{"https":true, "http":true}
supportedGitPullMethods = map[string]bool{"https": true, "http": true}
)
// Git unifies calls to download and unpack the build context.

View File

@ -1,42 +1,66 @@
package buildcontext
import (
"github.com/GoogleContainerTools/kaniko/testutil"
"os"
"testing"
"github.com/GoogleContainerTools/kaniko/testutil"
)
func TestGetGitPullMethod(t *testing.T) {
tests := []struct {
setEnv func()
expectedValue string
testName string
setEnv func() (expectedValue string)
}{
{
setEnv: func() {},
expectedValue: "https",
},
{
setEnv: func() {
_ = os.Setenv(gitPullMethodEnvKey, "http")
testName: "noEnv",
setEnv: func() (expectedValue string) {
expectedValue = "https"
return
},
expectedValue: "http",
},
{
setEnv: func() {
testName: "emptyEnv",
setEnv: func() (expectedValue string) {
_ = os.Setenv(gitPullMethodEnvKey, "")
expectedValue = "https"
return
},
},
{
testName: "httpEnv",
setEnv: func() (expectedValue string) {
err := os.Setenv(gitPullMethodEnvKey, "http")
if nil != err {
expectedValue = "https"
} else {
expectedValue = "http"
}
return
},
},
{
testName: "httpsEnv",
setEnv: func() (expectedValue string) {
_ = os.Setenv(gitPullMethodEnvKey, "https")
expectedValue = "https"
return
},
expectedValue: "https",
},
{
setEnv: func() {
testName: "unknownEnv",
setEnv: func() (expectedValue string) {
_ = os.Setenv(gitPullMethodEnvKey, "unknown")
expectedValue = "https"
return
},
expectedValue: "https",
},
}
for _, tt := range tests {
tt.setEnv()
testutil.CheckDeepEqual(t, getGitPullMethod(), tt.expectedValue)
t.Run(tt.testName, func(t *testing.T) {
expectedValue := tt.setEnv()
testutil.CheckDeepEqual(t, getGitPullMethod(), expectedValue)
})
}
}