Skip to content

Commit

Permalink
minor edit
Browse files Browse the repository at this point in the history
  • Loading branch information
jmnote committed Aug 11, 2024
1 parent 23f7e4b commit 354b2de
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
16 changes: 16 additions & 0 deletions internal/controller/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import (
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/manager"
)

func newScheme() *runtime.Scheme {
Expand All @@ -22,6 +25,19 @@ func newFakeClient(objs ...client.Object) client.Client {
return fake.NewClientBuilder().WithScheme(newScheme()).WithObjects(objs...).Build()
}

func newFakeManager() manager.Manager {
fakeConfig := &rest.Config{
Host: "https://fake-api-server",
}
mgr, err := ctrl.NewManager(fakeConfig, ctrl.Options{
Scheme: newScheme(),
})
if err != nil {
panic(err)
}
return mgr
}

type BadClient1 struct {
client.Client
}
Expand Down
13 changes: 2 additions & 11 deletions internal/controller/configmap_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -84,25 +83,17 @@ func TestConfigMapReconciler_SetupWithManager(t *testing.T) {
t.Log(222)

fakeClient := newFakeClient(tc.objects...)
fakeClientFunc := func(config *rest.Config, options client.Options) (client.Client, error) {
return fakeClient, nil
}
reconciler := &ConfigMapReconciler{
Client: fakeClient,
Scheme: newScheme(),
RulesStore: rulesstore.New(),
}
t.Log(333)

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: newScheme(),
NewClient: fakeClientFunc,
})
t.Log(444)
assert.NoError(t, err)
mgr := newFakeManager()
t.Log(555)

err = reconciler.SetupWithManager(mgr)
err := reconciler.SetupWithManager(mgr)
t.Log(666)
if tc.wantError != "" {
assert.ErrorContains(t, err, tc.wantError)
Expand Down
7 changes: 2 additions & 5 deletions internal/controller/ingress_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ func TestSetupWithManager(t *testing.T) {
Scheme: newScheme(),
RulesStore: mockRulesStore,
}
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: newScheme(),
})
assert.NoError(t, err)

err = reconciler.SetupWithManager(mgr)
mgr := newFakeManager()
err := reconciler.SetupWithManager(mgr)
assert.NoError(t, err)
}

Expand Down

0 comments on commit 354b2de

Please sign in to comment.