Skip to content

Commit

Permalink
Fake k8s context for tests
Browse files Browse the repository at this point in the history
Fixes GoogleContainerTools#1787

Signed-off-by: David Gageot <[email protected]>
  • Loading branch information
dgageot committed Mar 13, 2019
1 parent 4aae6af commit c084f0b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/skaffold/build/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/GoogleContainerTools/skaffold/testutil"
"github.com/docker/docker/api/types"
yaml "gopkg.in/yaml.v2"
"k8s.io/client-go/tools/clientcmd/api"
)

var (
Expand Down Expand Up @@ -122,6 +123,8 @@ func Test_NewCache(t *testing.T) {

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

cacheFile := createTempCacheFile(t, test.cacheFileContents)
if test.updateCacheFile {
Expand Down
10 changes: 10 additions & 0 deletions pkg/skaffold/runner/dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/sync"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/watch"
"github.com/GoogleContainerTools/skaffold/testutil"
"k8s.io/client-go/tools/clientcmd/api"
)

type NoopWatcher struct{}
Expand Down Expand Up @@ -92,6 +93,9 @@ func discardOutput() *config.Output {
}

func TestDevFailFirstCycle(t *testing.T) {
restore := testutil.SetupFakeKubernetesContext(t, api.Config{CurrentContext: "cluster1"})
defer restore()

var tests = []struct {
description string
testBench *TestBench
Expand Down Expand Up @@ -148,6 +152,9 @@ func TestDevFailFirstCycle(t *testing.T) {
}

func TestDev(t *testing.T) {
restore := testutil.SetupFakeKubernetesContext(t, api.Config{CurrentContext: "cluster1"})
defer restore()

var tests = []struct {
description string
testBench *TestBench
Expand Down Expand Up @@ -280,6 +287,9 @@ func TestDev(t *testing.T) {
}

func TestDevSync(t *testing.T) {
restore := testutil.SetupFakeKubernetesContext(t, api.Config{CurrentContext: "cluster1"})
defer restore()

var tests = []struct {
description string
testBench *TestBench
Expand Down
3 changes: 3 additions & 0 deletions pkg/skaffold/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ func TestNewForConfig(t *testing.T) {
}

func TestRun(t *testing.T) {
restore := testutil.SetupFakeKubernetesContext(t, api.Config{CurrentContext: "cluster1"})
defer restore()

var tests = []struct {
description string
testBench *TestBench
Expand Down

0 comments on commit c084f0b

Please sign in to comment.