diff --git a/test/support/client.go b/test/support/client.go index 66d2639..fca8a36 100644 --- a/test/support/client.go +++ b/test/support/client.go @@ -1,9 +1,7 @@ package support import ( - "errors" - "os" - "path/filepath" + "sigs.k8s.io/controller-runtime/pkg/client/config" "github.com/dapr-sandbox/dapr-kubernetes-operator/test/support/helm" @@ -14,8 +12,6 @@ import ( "k8s.io/client-go/discovery" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" - "k8s.io/client-go/tools/clientcmd" - "k8s.io/client-go/util/homedir" ) type Client struct { @@ -32,19 +28,7 @@ type Client struct { } func newClient(logFn func(string, ...interface{})) (*Client, error) { - kc := os.Getenv("KUBECONFIG") - if kc == "" { - home := homedir.HomeDir() - if home != "" { - kc = filepath.Join(home, ".kube", "config") - } - } - - if kc == "" { - return nil, errors.New("unable to determine KUBECONFIG") - } - - cfg, err := clientcmd.BuildConfigFromFlags("", kc) + cfg, err := config.GetConfig() if err != nil { return nil, err } diff --git a/test/support/test.go b/test/support/test.go index defde05..67a18f2 100644 --- a/test/support/test.go +++ b/test/support/test.go @@ -50,15 +50,6 @@ type Option[T any] interface { applyTo(to T) error } -type errorOption[T any] func(to T) error - -//nolint:unused -func (o errorOption[T]) applyTo(to T) error { - return o(to) -} - -var _ Option[any] = errorOption[any](nil) - func With(t *testing.T) Test { t.Helper() @@ -88,10 +79,10 @@ func With(t *testing.T) Test { type T struct { *gomega.WithT - t *testing.T - client *Client - once sync.Once - http *http.Client + t *testing.T + client *Client + clientOnce sync.Once + http *http.Client //nolint:containedctx ctx context.Context @@ -106,7 +97,7 @@ func (t *T) Ctx() context.Context { } func (t *T) Client() *Client { - t.once.Do(func() { + t.clientOnce.Do(func() { c, err := newClient(t.t.Logf) if err != nil { t.T().Fatalf("Error creating client: %v", err) @@ -117,10 +108,6 @@ func (t *T) Client() *Client { } func (t *T) HTTPClient() *http.Client { - t.once.Do(func() { - t.http = cleanhttp.DefaultClient() - }) - return t.http }