Skip to content

Commit 3f8eba0

Browse files
committed
Fake Kubernetes context for tests
Fixes GoogleContainerTools#1787 Signed-off-by: David Gageot <[email protected]>
1 parent 4aae6af commit 3f8eba0

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

pkg/skaffold/build/cache/cache_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/GoogleContainerTools/skaffold/testutil"
3131
"github.com/docker/docker/api/types"
3232
yaml "gopkg.in/yaml.v2"
33+
"k8s.io/client-go/tools/clientcmd/api"
3334
)
3435

3536
var (
@@ -122,6 +123,8 @@ func Test_NewCache(t *testing.T) {
122123

123124
for _, test := range tests {
124125
t.Run(test.name, func(t *testing.T) {
126+
restore := testutil.SetupFakeKubernetesContext(t, api.Config{CurrentContext: "cluster1"})
127+
defer restore()
125128

126129
cacheFile := createTempCacheFile(t, test.cacheFileContents)
127130
if test.updateCacheFile {

pkg/skaffold/runner/dev_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/sync"
2929
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/watch"
3030
"github.com/GoogleContainerTools/skaffold/testutil"
31+
"k8s.io/client-go/tools/clientcmd/api"
3132
)
3233

3334
type NoopWatcher struct{}
@@ -92,6 +93,9 @@ func discardOutput() *config.Output {
9293
}
9394

9495
func TestDevFailFirstCycle(t *testing.T) {
96+
restore := testutil.SetupFakeKubernetesContext(t, api.Config{CurrentContext: "cluster1"})
97+
defer restore()
98+
9599
var tests = []struct {
96100
description string
97101
testBench *TestBench
@@ -148,6 +152,9 @@ func TestDevFailFirstCycle(t *testing.T) {
148152
}
149153

150154
func TestDev(t *testing.T) {
155+
restore := testutil.SetupFakeKubernetesContext(t, api.Config{CurrentContext: "cluster1"})
156+
defer restore()
157+
151158
var tests = []struct {
152159
description string
153160
testBench *TestBench
@@ -280,6 +287,9 @@ func TestDev(t *testing.T) {
280287
}
281288

282289
func TestDevSync(t *testing.T) {
290+
restore := testutil.SetupFakeKubernetesContext(t, api.Config{CurrentContext: "cluster1"})
291+
defer restore()
292+
283293
var tests = []struct {
284294
description string
285295
testBench *TestBench

pkg/skaffold/runner/runner_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ func TestNewForConfig(t *testing.T) {
290290
}
291291

292292
func TestRun(t *testing.T) {
293+
restore := testutil.SetupFakeKubernetesContext(t, api.Config{CurrentContext: "cluster1"})
294+
defer restore()
295+
293296
var tests = []struct {
294297
description string
295298
testBench *TestBench

0 commit comments

Comments
 (0)