Skip to content

Commit

Permalink
Update controller tests to handle new fake client requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancoleman committed Apr 23, 2024
1 parent 84dea6c commit af32135
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ func TestGatewayClassReconciler(t *testing.T) {
objs = append(objs, tc.gatewayClass)
}

fakeClient := registerFieldIndexersForTest(fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(objs...)).Build()
fakeClient := registerFieldIndexersForTest(
fake.NewClientBuilder().WithScheme(s).
WithRuntimeObjects(objs...).
WithStatusSubresource(&gwv1beta1.GatewayClass{})).Build()

r := &GatewayClassController{
Client: fakeClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestGatewayClassConfigReconcile(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "consul-api-gateway",
DeletionTimestamp: &deletionTimestamp,
Finalizers: []string{gatewayClassConfigFinalizer},
},
}
return []runtime.Object{&gatewayClassConfig}
Expand All @@ -68,6 +69,7 @@ func TestGatewayClassConfigReconcile(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "consul-api-gateway",
DeletionTimestamp: &deletionTimestamp,
Finalizers: []string{gatewayClassConfigFinalizer},
},
}
gatewayClass := gwv1beta1.GatewayClass{
Expand Down Expand Up @@ -98,7 +100,10 @@ func TestGatewayClassConfigReconcile(t *testing.T) {
require.NoError(t, gwv1beta1.Install(s))
require.NoError(t, v1alpha1.AddToScheme(s))

fakeClient := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(tt.k8sObjects()...).Build()
fakeClient := fake.NewClientBuilder().WithScheme(s).
WithRuntimeObjects(tt.k8sObjects()...).
WithStatusSubresource(&v1alpha1.GatewayClassConfig{}).
Build()

// Create the gateway class config controller.
gcc := &GatewayClassConfigController{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,10 @@ func TestReconcile_CreateUpdatePeeringAcceptor(t *testing.T) {
s := runtime.NewScheme()
corev1.AddToScheme(s)
s.AddKnownTypes(v1alpha1.GroupVersion, &v1alpha1.PeeringAcceptor{}, &v1alpha1.PeeringAcceptorList{})
fakeClient := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(k8sObjects...).Build()
fakeClient := fake.NewClientBuilder().WithScheme(s).
WithRuntimeObjects(k8sObjects...).
WithStatusSubresource(&v1alpha1.PeeringAcceptor{}).
Build()

// Create test consul server.
testClient := test.TestServerWithMockConnMgrWatcher(t, nil)
Expand Down Expand Up @@ -627,7 +630,10 @@ func TestReconcile_DeletePeeringAcceptor(t *testing.T) {
s := runtime.NewScheme()
corev1.AddToScheme(s)
s.AddKnownTypes(v1alpha1.GroupVersion, &v1alpha1.PeeringAcceptor{}, &v1alpha1.PeeringAcceptorList{})
fakeClient := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(k8sObjects...).Build()
fakeClient := fake.NewClientBuilder().WithScheme(s).
WithRuntimeObjects(k8sObjects...).
WithStatusSubresource(&v1alpha1.PeeringAcceptor{}).
Build()

// Create test consulServer server
// Create test consul server.
Expand Down Expand Up @@ -775,7 +781,10 @@ func TestReconcile_VersionAnnotation(t *testing.T) {
s := runtime.NewScheme()
corev1.AddToScheme(s)
s.AddKnownTypes(v1alpha1.GroupVersion, &v1alpha1.PeeringAcceptor{}, &v1alpha1.PeeringAcceptorList{})
fakeClient := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(k8sObjects...).Build()
fakeClient := fake.NewClientBuilder().WithScheme(s).
WithRuntimeObjects(k8sObjects...).
WithStatusSubresource(&v1alpha1.PeeringAcceptor{}).
Build()

// Create test consul server.
testClient := test.TestServerWithMockConnMgrWatcher(t, nil)
Expand Down Expand Up @@ -1089,7 +1098,10 @@ func TestAcceptorUpdateStatus(t *testing.T) {
s := runtime.NewScheme()
corev1.AddToScheme(s)
s.AddKnownTypes(v1alpha1.GroupVersion, &v1alpha1.PeeringAcceptor{}, &v1alpha1.PeeringAcceptorList{})
fakeClient := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(k8sObjects...).Build()
fakeClient := fake.NewClientBuilder().WithScheme(s).
WithRuntimeObjects(k8sObjects...).
WithStatusSubresource(&v1alpha1.PeeringAcceptor{}).
Build()
// Create the peering acceptor controller.
pac := &AcceptorController{
Client: fakeClient,
Expand Down Expand Up @@ -1202,7 +1214,10 @@ func TestAcceptorUpdateStatusError(t *testing.T) {
s := runtime.NewScheme()
corev1.AddToScheme(s)
s.AddKnownTypes(v1alpha1.GroupVersion, &v1alpha1.PeeringAcceptor{}, &v1alpha1.PeeringAcceptorList{})
fakeClient := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(k8sObjects...).Build()
fakeClient := fake.NewClientBuilder().WithScheme(s).
WithRuntimeObjects(k8sObjects...).
WithStatusSubresource(&v1alpha1.PeeringAcceptor{}).
Build()
// Create the peering acceptor controller.
controller := &AcceptorController{
Client: fakeClient,
Expand All @@ -1219,6 +1234,7 @@ func TestAcceptorUpdateStatusError(t *testing.T) {
}
err := fakeClient.Get(context.Background(), acceptorName, acceptor)
require.NoError(t, err)
require.Len(t, acceptor.Status.Conditions, 1)
require.Equal(t, tt.expStatus.Conditions[0].Message, acceptor.Status.Conditions[0].Message)

})
Expand Down Expand Up @@ -1487,7 +1503,10 @@ func TestAcceptor_RequestsForPeeringTokens(t *testing.T) {
s := runtime.NewScheme()
corev1.AddToScheme(s)
s.AddKnownTypes(v1alpha1.GroupVersion, &v1alpha1.PeeringAcceptor{}, &v1alpha1.PeeringAcceptorList{})
fakeClient := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(tt.secret, &tt.acceptors).Build()
fakeClient := fake.NewClientBuilder().WithScheme(s).
WithRuntimeObjects(tt.secret, &tt.acceptors).
WithStatusSubresource(&v1alpha1.PeeringAcceptor{}).
Build()
controller := AcceptorController{
Client: fakeClient,
Log: logrtest.New(t),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,10 @@ func TestReconcile_CreateUpdatePeeringDialer(t *testing.T) {
s := runtime.NewScheme()
corev1.AddToScheme(s)
s.AddKnownTypes(v1alpha1.GroupVersion, &v1alpha1.PeeringDialer{}, &v1alpha1.PeeringDialerList{})
fakeClient := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(k8sObjects...).Build()
fakeClient := fake.NewClientBuilder().WithScheme(s).
WithRuntimeObjects(k8sObjects...).
WithStatusSubresource(&v1alpha1.PeeringDialer{}).
Build()

// Create the peering dialer controller
controller := &PeeringDialerController{
Expand Down Expand Up @@ -537,7 +540,10 @@ func TestReconcile_VersionAnnotationPeeringDialer(t *testing.T) {
s := runtime.NewScheme()
corev1.AddToScheme(s)
s.AddKnownTypes(v1alpha1.GroupVersion, &v1alpha1.PeeringDialer{}, &v1alpha1.PeeringDialerList{})
fakeClient := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(k8sObjects...).Build()
fakeClient := fake.NewClientBuilder().WithScheme(s).
WithRuntimeObjects(k8sObjects...).
WithStatusSubresource(&v1alpha1.PeeringDialer{}).
Build()

// Create the peering dialer controller
controller := &PeeringDialerController{
Expand Down Expand Up @@ -754,7 +760,10 @@ func TestReconcileDeletePeeringDialer(t *testing.T) {
s := runtime.NewScheme()
corev1.AddToScheme(s)
s.AddKnownTypes(v1alpha1.GroupVersion, &v1alpha1.PeeringDialer{}, &v1alpha1.PeeringDialerList{})
fakeClient := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(k8sObjects...).Build()
fakeClient := fake.NewClientBuilder().WithScheme(s).
WithRuntimeObjects(k8sObjects...).
WithStatusSubresource(&v1alpha1.PeeringDialer{}).
Build()

// Create test consul server.
testClient := test.TestServerWithMockConnMgrWatcher(t, nil)
Expand Down Expand Up @@ -897,7 +906,10 @@ func TestDialerUpdateStatus(t *testing.T) {
s := runtime.NewScheme()
corev1.AddToScheme(s)
s.AddKnownTypes(v1alpha1.GroupVersion, &v1alpha1.PeeringDialer{}, &v1alpha1.PeeringDialerList{})
fakeClient := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(k8sObjects...).Build()
fakeClient := fake.NewClientBuilder().WithScheme(s).
WithRuntimeObjects(k8sObjects...).
WithStatusSubresource(&v1alpha1.PeeringDialer{}).
Build()
// Create the peering dialer controller.
controller := &PeeringDialerController{
Client: fakeClient,
Expand Down Expand Up @@ -1010,7 +1022,11 @@ func TestDialerUpdateStatusError(t *testing.T) {
s := runtime.NewScheme()
corev1.AddToScheme(s)
s.AddKnownTypes(v1alpha1.GroupVersion, &v1alpha1.PeeringDialer{}, &v1alpha1.PeeringDialerList{})
fakeClient := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(k8sObjects...).Build()
fakeClient := fake.NewClientBuilder().WithScheme(s).
WithRuntimeObjects(k8sObjects...).
WithStatusSubresource(&v1alpha1.PeeringDialer{}).
Build()

// Create the peering dialer controller.
controller := &PeeringDialerController{
Client: fakeClient,
Expand All @@ -1027,6 +1043,7 @@ func TestDialerUpdateStatusError(t *testing.T) {
}
err := fakeClient.Get(context.Background(), dialerName, dialer)
require.NoError(t, err)
require.Len(t, dialer.Status.Conditions, 1)
require.Equal(t, tt.expStatus.Conditions[0].Message, dialer.Status.Conditions[0].Message)

})
Expand Down Expand Up @@ -1295,7 +1312,10 @@ func TestDialer_RequestsForPeeringTokens(t *testing.T) {
s := runtime.NewScheme()
corev1.AddToScheme(s)
s.AddKnownTypes(v1alpha1.GroupVersion, &v1alpha1.PeeringDialer{}, &v1alpha1.PeeringDialerList{})
fakeClient := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(tt.secret, &tt.dialers).Build()
fakeClient := fake.NewClientBuilder().WithScheme(s).
WithRuntimeObjects(tt.secret, &tt.dialers).
WithStatusSubresource(&v1alpha1.PeeringDialer{}).
Build()
controller := PeeringDialerController{
Client: fakeClient,
Log: logrtest.New(t),
Expand Down

0 comments on commit af32135

Please sign in to comment.