Skip to content

Commit

Permalink
Add minimal device controller test
Browse files Browse the repository at this point in the history
  • Loading branch information
janekbaraniewski committed Apr 26, 2022
1 parent 3382dda commit 6170936
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions pkg/controllers/device_controller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package controllers

import (
"context"
"testing"

"github.com/janekbaraniewski/kubeserial/pkg/apis/kubeserial/v1alpha1"
"github.com/stretchr/testify/assert"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
controllerruntime "sigs.k8s.io/controller-runtime"
runtimefake "sigs.k8s.io/controller-runtime/pkg/client/fake"
)

func TestDeviceReconciler_Reconcile(t *testing.T) {
deviceName := types.NamespacedName{
Name: "test-device",
Namespace: "test-ns",
}

device := &v1alpha1.Device{
ObjectMeta: v1.ObjectMeta{
Name: deviceName.Name,
Namespace: deviceName.Namespace,
},
}
scheme := runtime.NewScheme()
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(v1alpha1.AddToScheme(scheme))
fakeClient := runtimefake.NewClientBuilder().WithScheme(scheme).Build()

err := fakeClient.Create(context.TODO(), device)

assert.Equal(t, nil, err)

deviceReconciler := DeviceReconciler{
Client: fakeClient,
Scheme: scheme,
}

result, err := deviceReconciler.Reconcile(context.TODO(), controllerruntime.Request{NamespacedName: deviceName})

assert.Equal(t, nil, err)
assert.Equal(t, false, result.Requeue)
}

0 comments on commit 6170936

Please sign in to comment.