modify code format and unit-test
This commit is contained in:
parent
4f8d074e00
commit
d8b8e811dd
|
|
@ -30,7 +30,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
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.
|
// Git unifies calls to download and unpack the build context.
|
||||||
|
|
|
||||||
|
|
@ -1,42 +1,66 @@
|
||||||
package buildcontext
|
package buildcontext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/GoogleContainerTools/kaniko/testutil"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/GoogleContainerTools/kaniko/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetGitPullMethod(t *testing.T) {
|
func TestGetGitPullMethod(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
setEnv func()
|
testName string
|
||||||
expectedValue string
|
setEnv func() (expectedValue string)
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
setEnv: func() {},
|
testName: "noEnv",
|
||||||
expectedValue: "https",
|
setEnv: func() (expectedValue string) {
|
||||||
},
|
expectedValue = "https"
|
||||||
{
|
return
|
||||||
setEnv: func() {
|
|
||||||
_ = os.Setenv(gitPullMethodEnvKey, "http")
|
|
||||||
},
|
},
|
||||||
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")
|
_ = os.Setenv(gitPullMethodEnvKey, "https")
|
||||||
|
expectedValue = "https"
|
||||||
|
return
|
||||||
},
|
},
|
||||||
expectedValue: "https",
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
setEnv: func() {
|
testName: "unknownEnv",
|
||||||
|
setEnv: func() (expectedValue string) {
|
||||||
_ = os.Setenv(gitPullMethodEnvKey, "unknown")
|
_ = os.Setenv(gitPullMethodEnvKey, "unknown")
|
||||||
|
expectedValue = "https"
|
||||||
|
return
|
||||||
},
|
},
|
||||||
expectedValue: "https",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
tt.setEnv()
|
t.Run(tt.testName, func(t *testing.T) {
|
||||||
testutil.CheckDeepEqual(t, getGitPullMethod(), tt.expectedValue)
|
expectedValue := tt.setEnv()
|
||||||
|
testutil.CheckDeepEqual(t, getGitPullMethod(), expectedValue)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue