Skip to content

Commit

Permalink
Update tests after modifications to fakeClient
Browse files Browse the repository at this point in the history
  • Loading branch information
burmanm committed Feb 27, 2024
1 parent 4395391 commit 69ed087
Show file tree
Hide file tree
Showing 8 changed files with 1,027 additions and 228 deletions.
2 changes: 1 addition & 1 deletion apis/config/v1beta1/operatorconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
cfg "sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
cfg "sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" //nolint:staticcheck
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand Down
1 change: 1 addition & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func main() {
operConfig := configv1beta1.OperatorConfig{}
options := ctrl.Options{Scheme: scheme}
if configFile != "" {
//nolint:staticcheck
options, err = options.AndFrom(ctrl.ConfigFile().AtPath(configFile).OfKind(&operConfig))
if err != nil {
setupLog.Error(err, "unable to load the config file")
Expand Down
1,205 changes: 994 additions & 211 deletions config/crd/bases/cassandra.datastax.com_cassandradatacenters.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"k8s.io/utils/pointer" //nolint:staticcheck
"sigs.k8s.io/controller-runtime/pkg/client"

cassdcapi "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1"
Expand Down
15 changes: 15 additions & 0 deletions pkg/mockhelper/http.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package mockhelper

import (
"net/http"

client "sigs.k8s.io/controller-runtime/pkg/client"
)

type Client interface {
client.Client
}

type HttpClient interface {
http.Client
}
2 changes: 1 addition & 1 deletion pkg/reconciliation/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/utils/pointer"
"k8s.io/utils/pointer" //nolint:staticcheck

"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down
24 changes: 12 additions & 12 deletions pkg/reconciliation/reconcile_racks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"testing"
"time"

"k8s.io/utils/pointer"
"k8s.io/utils/pointer" //nolint:staticcheck

api "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1"
taskapi "github.com/k8ssandra/cass-operator/apis/control/v1alpha1"
Expand Down Expand Up @@ -227,7 +227,7 @@ func TestReconcileRacks_ReconcilePods(t *testing.T) {
trackObjects = append(trackObjects, mp)
}

rc.Client = fake.NewClientBuilder().WithRuntimeObjects(trackObjects...).Build()
rc.Client = fake.NewClientBuilder().WithStatusSubresource(rc.Datacenter).WithRuntimeObjects(trackObjects...).Build()

nextRack := &RackInformation{}
nextRack.RackName = "default"
Expand Down Expand Up @@ -448,7 +448,7 @@ func TestReconcilePods_WithVolumes(t *testing.T) {
pvc,
}

rc.Client = fake.NewClientBuilder().WithRuntimeObjects(trackObjects...).Build()
rc.Client = fake.NewClientBuilder().WithStatusSubresource(pod, pvc).WithRuntimeObjects(trackObjects...).Build()
err = rc.ReconcilePods(statefulSet)
assert.NoErrorf(t, err, "Should not have returned an error")
}
Expand Down Expand Up @@ -580,7 +580,7 @@ func TestReconcileRacks(t *testing.T) {
trackObjects = append(trackObjects, mp)
}

rc.Client = fake.NewClientBuilder().WithRuntimeObjects(trackObjects...).Build()
rc.Client = fake.NewClientBuilder().WithStatusSubresource(desiredStatefulSet, rc.Datacenter).WithRuntimeObjects(trackObjects...).Build()

var rackInfo []*RackInformation

Expand Down Expand Up @@ -652,7 +652,7 @@ func TestReconcileRacks_WaitingForReplicas(t *testing.T) {
trackObjects = append(trackObjects, mp)
}

rc.Client = fake.NewClientBuilder().WithRuntimeObjects(trackObjects...).Build()
rc.Client = fake.NewClientBuilder().WithStatusSubresource(desiredStatefulSet).WithRuntimeObjects(trackObjects...).Build()

var rackInfo []*RackInformation

Expand Down Expand Up @@ -688,7 +688,7 @@ func TestReconcileRacks_NeedMoreReplicas(t *testing.T) {
preExistingStatefulSet,
}

rc.Client = fake.NewClientBuilder().WithRuntimeObjects(trackObjects...).Build()
rc.Client = fake.NewClientBuilder().WithStatusSubresource(preExistingStatefulSet).WithRuntimeObjects(trackObjects...).Build()

var rackInfo []*RackInformation

Expand Down Expand Up @@ -729,7 +729,7 @@ func TestReconcileRacks_DoesntScaleDown(t *testing.T) {
trackObjects = append(trackObjects, mp)
}

rc.Client = fake.NewClientBuilder().WithRuntimeObjects(trackObjects...).Build()
rc.Client = fake.NewClientBuilder().WithStatusSubresource(preExistingStatefulSet).WithRuntimeObjects(trackObjects...).Build()

var rackInfo []*RackInformation

Expand Down Expand Up @@ -765,7 +765,7 @@ func TestReconcileRacks_NeedToPark(t *testing.T) {
rc.Datacenter,
}

rc.Client = fake.NewClientBuilder().WithRuntimeObjects(trackObjects...).Build()
rc.Client = fake.NewClientBuilder().WithStatusSubresource(preExistingStatefulSet, rc.Datacenter).WithRuntimeObjects(trackObjects...).Build()

var rackInfo []*RackInformation

Expand Down Expand Up @@ -815,7 +815,7 @@ func TestReconcileRacks_AlreadyReconciled(t *testing.T) {
desiredPdb,
}

rc.Client = fake.NewClientBuilder().WithRuntimeObjects(trackObjects...).Build()
rc.Client = fake.NewClientBuilder().WithStatusSubresource(desiredStatefulSet, rc.Datacenter, desiredPdb).WithRuntimeObjects(trackObjects...).Build()

var rackInfo []*RackInformation

Expand Down Expand Up @@ -888,7 +888,7 @@ func TestReconcileRacks_FirstRackAlreadyReconciled(t *testing.T) {
rc.Datacenter,
}

rc.Client = fake.NewClientBuilder().WithRuntimeObjects(trackObjects...).Build()
rc.Client = fake.NewClientBuilder().WithStatusSubresource(desiredStatefulSet, secondDesiredStatefulSet, rc.Datacenter).WithRuntimeObjects(trackObjects...).Build()

var rackInfo []*RackInformation

Expand Down Expand Up @@ -958,7 +958,7 @@ func TestReconcileRacks_UpdateRackNodeCount(t *testing.T) {
rc.Datacenter,
}

rc.Client = fake.NewClientBuilder().WithRuntimeObjects(trackObjects...).Build()
rc.Client = fake.NewClientBuilder().WithStatusSubresource(tt.args.statefulSet, rc.Datacenter).WithRuntimeObjects(trackObjects...).Build()

if err := rc.UpdateRackNodeCount(tt.args.statefulSet, tt.args.newNodeCount); (err != nil) != tt.wantErr {
t.Errorf("updateRackNodeCount() error = %v, wantErr %v", err, tt.wantErr)
Expand Down Expand Up @@ -999,7 +999,7 @@ func TestReconcileRacks_UpdateConfig(t *testing.T) {
trackObjects = append(trackObjects, mp)
}

rc.Client = fake.NewClientBuilder().WithRuntimeObjects(trackObjects...).Build()
rc.Client = fake.NewClientBuilder().WithStatusSubresource(desiredStatefulSet, rc.Datacenter, desiredPdb).WithRuntimeObjects(trackObjects...).Build()

var rackInfo []*RackInformation

Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciliation/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func CreateMockReconciliationContext(
s := scheme.Scheme
s.AddKnownTypes(api.GroupVersion, cassandraDatacenter)

fakeClient := fake.NewClientBuilder().WithRuntimeObjects(trackObjects...).Build()
fakeClient := fake.NewClientBuilder().WithStatusSubresource(cassandraDatacenter).WithRuntimeObjects(trackObjects...).Build()

request := &reconcile.Request{
NamespacedName: types.NamespacedName{
Expand Down Expand Up @@ -146,7 +146,7 @@ func fakeClientWithService(cassandraDatacenter *api.CassandraDatacenter) (*clien
service,
}

fakeClient := fake.NewClientBuilder().WithRuntimeObjects(trackObjects...).Build()
fakeClient := fake.NewClientBuilder().WithStatusSubresource(cassandraDatacenter, service).WithRuntimeObjects(trackObjects...).Build()

return &fakeClient, service
}
Expand Down

0 comments on commit 69ed087

Please sign in to comment.