Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cleanup e2e test support #59

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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