From 4f8d074e00aac7105cc8d8d9cf3b1c7a5d6edbad Mon Sep 17 00:00:00 2001 From: yw-liu <43599588+yw-liu@users.noreply.github.com> Date: Thu, 16 Apr 2020 22:21:09 +0800 Subject: [PATCH] add unit-test --- pkg/buildcontext/git_test.go | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 pkg/buildcontext/git_test.go diff --git a/pkg/buildcontext/git_test.go b/pkg/buildcontext/git_test.go new file mode 100644 index 000000000..c56159b95 --- /dev/null +++ b/pkg/buildcontext/git_test.go @@ -0,0 +1,42 @@ +package buildcontext + +import ( + "github.com/GoogleContainerTools/kaniko/testutil" + "os" + "testing" +) + +func TestGetGitPullMethod(t *testing.T) { + tests := []struct { + setEnv func() + expectedValue string + }{ + { + setEnv: func() {}, + expectedValue: "https", + }, + { + setEnv: func() { + _ = os.Setenv(gitPullMethodEnvKey, "http") + }, + expectedValue: "http", + }, + { + setEnv: func() { + _ = os.Setenv(gitPullMethodEnvKey, "https") + }, + expectedValue: "https", + }, + { + setEnv: func() { + _ = os.Setenv(gitPullMethodEnvKey, "unknown") + }, + expectedValue: "https", + }, + } + + for _, tt := range tests { + tt.setEnv() + testutil.CheckDeepEqual(t, getGitPullMethod(), tt.expectedValue) + } +}