Skip to content

Commit

Permalink
test: adding test, fixing others
Browse files Browse the repository at this point in the history
  • Loading branch information
trutx committed Nov 19, 2024
1 parent 9d180a8 commit e3c3910
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,27 @@ func TestPluginManager_AddObjectMetadata(t *testing.T) {
assert.Equal(t, 0, len(o.GetFinalizers()))
})

t.Run("Inject finalizers", func(t *testing.T) {
p := pluginsk8sMock.Plugin{}
p.OnGetProperties().Return(k8s.PluginProperties{DisableInjectFinalizer: false})
pluginManager := PluginManager{plugin: &p}
// enable finalizer injection
cfg.InjectFinalizer = true
o := &v1.Pod{}
pluginManager.addObjectMetadata(tm, o, cfg)
assert.Equal(t, genName, o.GetName())
// empty OwnerReference since we are ignoring
assert.Equal(t, 1, len(o.GetOwnerReferences()))
assert.Equal(t, ns, o.GetNamespace())
assert.Equal(t, map[string]string{
"cluster-autoscaler.kubernetes.io/safe-to-evict": "false",
"aKey": "aVal",
}, o.GetAnnotations())
assert.Equal(t, l, o.GetLabels())
assert.Equal(t, 1, len(o.GetFinalizers()))
assert.Contains(t, o.GetFinalizers(), finalizer)
})

}

func TestResourceManagerConstruction(t *testing.T) {
Expand Down Expand Up @@ -1023,7 +1044,7 @@ func TestFinalize(t *testing.T) {
assert.NoError(t, fakeKubeClient.GetClient().Create(ctx, o))

p.OnBuildIdentityResource(ctx, tctx.TaskExecutionMetadata()).Return(o, nil)
pluginManager := PluginManager{plugin: &p, kubeClient: fakeKubeClient}
pluginManager := PluginManager{plugin: &p, kubeClient: fakeKubeClient, updateBackoffRetries: 5}
actualO := &v1.Pod{}
// Assert the object exists before calling finalize
assert.NoError(t, fakeKubeClient.GetClient().Get(ctx, k8stypes.NamespacedName{
Expand Down Expand Up @@ -1061,7 +1082,7 @@ func TestFinalize(t *testing.T) {
assert.NoError(t, fakeKubeClient.GetClient().Create(ctx, o))

p.OnBuildIdentityResource(ctx, tctx.TaskExecutionMetadata()).Return(o, nil)
pluginManager := PluginManager{plugin: &p, kubeClient: fakeKubeClient}
pluginManager := PluginManager{plugin: &p, kubeClient: fakeKubeClient, updateBackoffRetries: 5}
actualO := &v1.Pod{}
// Assert the object exists before calling finalize
assert.NoError(t, fakeKubeClient.GetClient().Get(ctx, k8stypes.NamespacedName{
Expand Down

0 comments on commit e3c3910

Please sign in to comment.