Skip to content

Commit

Permalink
chore: cleanup e2e test support
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Burgazzoli <[email protected]>
  • Loading branch information
lburgazzoli committed Nov 14, 2023
1 parent 00ae389 commit 9c9cda7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 36 deletions.
20 changes: 2 additions & 18 deletions test/support/client.go
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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 {
Expand All @@ -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
}
Expand Down
23 changes: 5 additions & 18 deletions test/support/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
}

Expand Down

0 comments on commit 9c9cda7

Please sign in to comment.