Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: remove dead event recorder code #408

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions pkg/bundle/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

trustapi "github.com/cert-manager/trust-manager/pkg/apis/trust/v1alpha1"
"github.com/cert-manager/trust-manager/pkg/bundle/internal/truststore"
Expand Down Expand Up @@ -1292,7 +1292,7 @@ func Test_Reconcile(t *testing.T) {
test := test
t.Run(name, func(t *testing.T) {
t.Parallel()
fakeclient := fakeclient.NewClientBuilder().
fakeClient := fake.NewClientBuilder().
WithScheme(trustapi.GlobalScheme).
WithObjects(deepCopyArray(test.existingConfigMaps)...).
WithObjects(deepCopyArray(test.existingBundles)...).
Expand All @@ -1302,7 +1302,7 @@ func Test_Reconcile(t *testing.T) {
WithStatusSubresource(deepCopyArray(test.existingBundles)...).
Build()

fakerecorder := record.NewFakeRecorder(1)
fakeRecorder := record.NewFakeRecorder(1)

var (
logMutex sync.Mutex
Expand All @@ -1311,9 +1311,9 @@ func Test_Reconcile(t *testing.T) {

log, ctx := ktesting.NewTestContext(t)
b := &bundle{
client: fakeclient,
targetCache: fakeclient,
recorder: fakerecorder,
client: fakeClient,
targetCache: fakeClient,
recorder: fakeRecorder,
clock: fixedclock,
Options: Options{
Log: log,
Expand Down Expand Up @@ -1346,7 +1346,7 @@ func Test_Reconcile(t *testing.T) {

var event string
select {
case event = <-fakerecorder.Events:
case event = <-fakeRecorder.Events:
default:
}
assert.Equal(t, test.expEvent, event)
Expand Down
4 changes: 2 additions & 2 deletions pkg/bundle/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,13 @@ func Test_buildSourceBundle(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

fakeclient := fake.NewClientBuilder().
fakeClient := fake.NewClientBuilder().
WithRuntimeObjects(test.objects...).
WithScheme(trustapi.GlobalScheme).
Build()

b := &bundle{
client: fakeclient,
client: fakeClient,
defaultPackage: &fspkg.Package{
Name: "testpkg",
Version: "123",
Expand Down
43 changes: 11 additions & 32 deletions pkg/bundle/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ import (
"k8s.io/apimachinery/pkg/runtime"
coreapplyconfig "k8s.io/client-go/applyconfigurations/core/v1"
metav1applyconfig "k8s.io/client-go/applyconfigurations/meta/v1"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2/ktesting"
"k8s.io/utils/ptr"
fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/structured-merge-diff/fieldpath"

trustapi "github.com/cert-manager/trust-manager/pkg/apis/trust/v1alpha1"
Expand Down Expand Up @@ -99,7 +98,6 @@ func Test_syncConfigMapTarget(t *testing.T) {
expJKS bool
// Expect PKCS12 to exist in the configmap at the end of the sync.
expPKCS12 bool
expEvent string
// Expect the owner reference of the configmap to point to the bundle.
expOwnerReference bool
expNeedsUpdate bool
Expand Down Expand Up @@ -441,7 +439,7 @@ func Test_syncConfigMapTarget(t *testing.T) {
expOwnerReference: true,
expNeedsUpdate: true,
},
"if object exists with correct data and some extra data (not owned by our fieldmanager) and owner, expect no update": {
"if object exists with correct data and some extra data (not owned by our field manager) and owner, expect no update": {
object: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: bundleName,
Expand Down Expand Up @@ -584,24 +582,22 @@ func Test_syncConfigMapTarget(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

clientBuilder := fakeclient.NewClientBuilder().
clientBuilder := fake.NewClientBuilder().
WithScheme(trustapi.GlobalScheme)
if test.object != nil {
clientBuilder.WithRuntimeObjects(test.object)
}

fakeclient := clientBuilder.Build()
fakerecorder := record.NewFakeRecorder(1)
fakeClient := clientBuilder.Build()

var (
logMutex sync.Mutex
resourcePatches []interface{}
)

b := &bundle{
client: fakeclient,
targetCache: fakeclient,
recorder: fakerecorder,
client: fakeClient,
targetCache: fakeClient,
patchResourceOverwrite: func(ctx context.Context, obj interface{}) error {
logMutex.Lock()
defer logMutex.Unlock()
Expand Down Expand Up @@ -686,13 +682,6 @@ func Test_syncConfigMapTarget(t *testing.T) {
assert.Equal(t, pkcs12Data, binData)
}
}

var event string
select {
case event = <-fakerecorder.Events:
default:
}
assert.Equal(t, test.expEvent, event)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or should we keep this to assert no events?

})
}
}
Expand All @@ -719,7 +708,6 @@ func Test_syncSecretTarget(t *testing.T) {
expJKS bool
// Expect PKCS12 to exist in the secret at the end of the sync.
expPKCS12 bool
expEvent string
// Expect the owner reference of the secret to point to the bundle.
expOwnerReference bool
expNeedsUpdate bool
Expand Down Expand Up @@ -1061,7 +1049,7 @@ func Test_syncSecretTarget(t *testing.T) {
expOwnerReference: true,
expNeedsUpdate: true,
},
"if object exists with correct data and some extra data (not owned by our fieldmanager) and owner, expect no update": {
"if object exists with correct data and some extra data (not owned by our field manager) and owner, expect no update": {
object: &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: bundleName,
Expand Down Expand Up @@ -1204,24 +1192,22 @@ func Test_syncSecretTarget(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

clientBuilder := fakeclient.NewClientBuilder().
clientBuilder := fake.NewClientBuilder().
WithScheme(trustapi.GlobalScheme)
if test.object != nil {
clientBuilder.WithRuntimeObjects(test.object)
}

fakeclient := clientBuilder.Build()
fakerecorder := record.NewFakeRecorder(1)
fakeClient := clientBuilder.Build()

var (
logMutex sync.Mutex
resourcePatches []interface{}
)

b := &bundle{
client: fakeclient,
targetCache: fakeclient,
recorder: fakerecorder,
client: fakeClient,
targetCache: fakeClient,
patchResourceOverwrite: func(ctx context.Context, obj interface{}) error {
logMutex.Lock()
defer logMutex.Unlock()
Expand Down Expand Up @@ -1304,13 +1290,6 @@ func Test_syncSecretTarget(t *testing.T) {
assert.Equal(t, pkcs12Data, binData)
}
}

var event string
select {
case event = <-fakerecorder.Events:
default:
}
assert.Equal(t, test.expEvent, event)
})
}
}