Skip to content

Commit

Permalink
fix unit tests (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelvillard committed Jun 10, 2020
1 parent 7f5fae6 commit db56628
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions pkg/reconciler/pingsource/pingsource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -75,6 +76,7 @@ const (
testNS = "testnamespace"
testSchedule = "*/2 * * * *"
testData = "data"
crName = "knative-eventing-pingsource-adapter"

sinkName = "testsink"
generation = 1
Expand Down Expand Up @@ -159,8 +161,14 @@ func TestAllCases(t *testing.T) {
},
Key: testNS + "/" + sourceName,
WantEvents: []string{
Eventf(corev1.EventTypeNormal, "PingSourceServiceAccountCreated", `PingSource ServiceAccount created`),
Eventf(corev1.EventTypeNormal, "PingSourceRoleBindingCreated", `PingSource RoleBinding created`),
Eventf(corev1.EventTypeNormal, "PingSourceReconciled", `PingSource reconciled: "%s/%s"`, testNS, sourceName),
},
WantCreates: []runtime.Object{
MakeServiceAccount(sourceName, sourceUID),
MakeRoleBinding(sourceName, sourceUID),
},
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: NewPingSourceV1Alpha2(sourceName, testNS,
WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{
Expand Down Expand Up @@ -205,8 +213,14 @@ func TestAllCases(t *testing.T) {
},
Key: testNS + "/" + sourceName,
WantEvents: []string{
Eventf(corev1.EventTypeNormal, "PingSourceServiceAccountCreated", `PingSource ServiceAccount created`),
Eventf(corev1.EventTypeNormal, "PingSourceRoleBindingCreated", `PingSource RoleBinding created`),
Eventf(corev1.EventTypeNormal, "PingSourceReconciled", `PingSource reconciled: "%s/%s"`, testNS, sourceName),
},
WantCreates: []runtime.Object{
MakeServiceAccount(sourceName, sourceUID),
MakeRoleBinding(sourceName, sourceUID),
},
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: NewPingSourceV1Alpha2(sourceName, testNS,
WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{
Expand Down Expand Up @@ -251,8 +265,14 @@ func TestAllCases(t *testing.T) {
},
Key: testNS + "/" + sourceName,
WantEvents: []string{
Eventf(corev1.EventTypeNormal, "PingSourceServiceAccountCreated", `PingSource ServiceAccount created`),
Eventf(corev1.EventTypeNormal, "PingSourceRoleBindingCreated", `PingSource RoleBinding created`),
Eventf(corev1.EventTypeNormal, "PingSourceReconciled", `PingSource reconciled: "%s/%s"`, testNS, sourceName),
},
WantCreates: []runtime.Object{
MakeServiceAccount(sourceName, sourceUID),
MakeRoleBinding(sourceName, sourceUID),
},
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: NewPingSourceV1Alpha2(sourceName, testNS,
WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{
Expand Down Expand Up @@ -299,6 +319,8 @@ func TestAllCases(t *testing.T) {
rtv1beta1.WithChannelAddress(sinkDNS),
),
makeAvailableReceiveAdapter(sinkDest),
MakeServiceAccount(sourceName, sourceUID),
MakeRoleBinding(sourceName, sourceUID),
},
Key: testNS + "/" + sourceName,
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Expand Down Expand Up @@ -348,8 +370,14 @@ func TestAllCases(t *testing.T) {
},
Key: testNS + "/" + sourceName,
WantEvents: []string{
Eventf(corev1.EventTypeNormal, "PingSourceServiceAccountCreated", `PingSource ServiceAccount created`),
Eventf(corev1.EventTypeNormal, "PingSourceRoleBindingCreated", `PingSource RoleBinding created`),
Eventf(corev1.EventTypeNormal, "PingSourceReconciled", `PingSource reconciled: "%s/%s"`, testNS, sourceName),
},
WantCreates: []runtime.Object{
MakeServiceAccount(sourceName, sourceUID),
MakeRoleBinding(sourceName, sourceUID),
},
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: NewPingSourceV1Alpha2(sourceName, testNS,
WithPingSourceV1A2Spec(sourcesv1alpha2.PingSourceSpec{
Expand Down Expand Up @@ -489,6 +517,8 @@ func TestAllCases(t *testing.T) {
rtv1beta1.WithChannelAddress(sinkDNS),
),
makeAvailableReceiveAdapterDeprecatedName(sourceNameLong, sourceUIDLong, sinkDest),
MakeServiceAccount(sourceNameLong, sourceUIDLong),
MakeRoleBinding(sourceNameLong, sourceUIDLong),
},
Key: testNS + "/" + sourceNameLong,
WantEvents: []string{
Expand Down Expand Up @@ -534,6 +564,8 @@ func TestAllCases(t *testing.T) {
kubeClientSet: fakekubeclient.Get(ctx),
pingLister: listers.GetPingSourceV1alpha2Lister(),
deploymentLister: listers.GetDeploymentLister(),
serviceAccountLister: listers.GetServiceAccountLister(),
roleBindingLister: listers.GetRoleBindingLister(),
tracker: tracker.New(func(types.NamespacedName) {}, 0),
receiveAdapterImage: image,
receiveMTAdapterImage: mtimage,
Expand Down Expand Up @@ -610,3 +642,15 @@ func makeAvailableMTAdapter() *appsv1.Deployment {
WithDeploymentAvailable()(ma)
return ma
}

func MakeServiceAccount(sourceName, sourceUID string) *corev1.ServiceAccount {
source := NewPingSourceV1Alpha2(sourceName, testNS,
WithPingSourceV1A2UID(sourceUID))
return resources.MakeServiceAccount(source, resources.CreateReceiveAdapterName(sourceName, types.UID(sourceUID)))
}

func MakeRoleBinding(sourceName, sourceUID string) *rbacv1.RoleBinding {
source := NewPingSourceV1Alpha2(sourceName, testNS,
WithPingSourceV1A2UID(sourceUID))
return resources.MakeRoleBinding(source, resources.CreateReceiveAdapterName(sourceName, types.UID(sourceUID)), crName)
}

0 comments on commit db56628

Please sign in to comment.