Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
test: adding setup/fail tests to meet 85% threshold (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
adorney99 authored and pbrownlow7 committed Aug 4, 2023
1 parent ef33d59 commit b8d42c9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
19 changes: 19 additions & 0 deletions controllers/cstates_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
"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/config/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

Expand Down Expand Up @@ -254,3 +256,20 @@ func setupFuzz(t *testing.T, nodeName string, namespace string, extraNode bool,

return buildCStatesReconcilerObject(objs, powerLib), req
}


// tests failure for SetupWithManager function
func TestCstate_Reconcile_SetupFail(t *testing.T) {
powerLibMock := new(hostMock)
r := buildCStatesReconcilerObject([]runtime.Object{}, powerLibMock)
mgr, _ := ctrl.NewManager(&rest.Config{}, ctrl.Options{
Scheme: scheme.Scheme,
})

err := (&CStatesReconciler{
Client: r.Client,
Scheme: r.Scheme,
}).SetupWithManager(mgr)
assert.Error(t, err)

}
36 changes: 36 additions & 0 deletions controllers/powerconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
"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/config/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

powerv1 "github.com/intel/kubernetes-power-manager/api/v1"
"github.com/intel/kubernetes-power-manager/pkg/state"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -695,3 +699,35 @@ func TestPowerConfig_Reconcile_Deletion(t *testing.T) {
}
}
}

// tests positive and negative cases for SetupWithManager function
func TestPowerConfig_Reconcile_SetupPass(t *testing.T) {
r, err := createConfigReconcilerObject([]runtime.Object{})
assert.Nil(t, err)
mgr := new(mgrMock)
mgr.On("GetControllerOptions").Return(v1alpha1.ControllerConfigurationSpec{})
mgr.On("GetScheme").Return(r.Scheme)
mgr.On("GetLogger").Return(r.Log)
mgr.On("SetFields", mock.Anything).Return(nil)
mgr.On("Add", mock.Anything).Return(nil)
err = (&PowerConfigReconciler{
Client: r.Client,
Scheme: r.Scheme,
}).SetupWithManager(mgr)
assert.Nil(t, err)

}
func TesPowerConfig_Reconcile_SetupFail(t *testing.T) {
r, err := createConfigReconcilerObject([]runtime.Object{})
assert.Nil(t, err)
mgr, _ := ctrl.NewManager(&rest.Config{}, ctrl.Options{
Scheme: scheme.Scheme,
})

err = (&PowerConfigReconciler{
Client: r.Client,
Scheme: r.Scheme,
}).SetupWithManager(mgr)
assert.Error(t, err)

}

0 comments on commit b8d42c9

Please sign in to comment.