Skip to content

Commit 8f64722

Browse files
authored
make tests work with the kubeconfig env by default, enable to override with a custom config (#20)
1 parent 1372ad2 commit 8f64722

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

main_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ import (
1818
"fmt"
1919
"log"
2020
"os"
21-
"path/filepath"
2221
"reflect"
2322
"testing"
2423

25-
patch "github.com/banzaicloud/k8s-objectmatcher/patch"
24+
"github.com/banzaicloud/k8s-objectmatcher/patch"
2625
"github.com/goph/emperror"
2726
"github.com/pkg/errors"
2827
admissionregistrationv1beta1 "k8s.io/api/admissionregistration/v1beta1"
@@ -40,13 +39,12 @@ import (
4039
"k8s.io/client-go/dynamic"
4140
"k8s.io/client-go/kubernetes"
4241
"k8s.io/client-go/tools/clientcmd"
43-
"k8s.io/client-go/util/homedir"
4442
"k8s.io/klog"
4543
)
4644

4745
var (
4846
integration = flag.Bool("integration", false, "run integration tests")
49-
kubeconfig = flag.String("kubeconfig", filepath.Join(homedir.HomeDir(), ".kube/config"), "kubernetes config to use for tests")
47+
kubeconfig = flag.String("kubeconfig", "", "kubernetes config to use for tests")
5048
kubecontext = flag.String("kubecontext", "", "kubernetes context to use in tests")
5149
keepnamespace = flag.Bool("keepnamespace", false, "keep the kubernetes namespace that was used for the tests")
5250
failonerror = flag.Bool("failonerror", false, "fail on error to be able to debug invalid state")
@@ -105,8 +103,12 @@ func (ctx *IntegrationTestContext) CreateNamespace() error {
105103
}
106104

107105
func (ctx *IntegrationTestContext) Setup() error {
106+
kubeconfigOverride := os.Getenv("KUBECONFIG")
107+
if *kubeconfig != "" {
108+
kubeconfigOverride = *kubeconfig
109+
}
108110
config, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
109-
&clientcmd.ClientConfigLoadingRules{ExplicitPath: *kubeconfig},
111+
&clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeconfigOverride},
110112
&clientcmd.ConfigOverrides{CurrentContext: *kubecontext},
111113
).ClientConfig()
112114
if err != nil {

0 commit comments

Comments
 (0)