-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpatch_framework_test.go
More file actions
49 lines (39 loc) · 1.62 KB
/
patch_framework_test.go
File metadata and controls
49 lines (39 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package hookinfolder_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/deckhouse/module-sdk/pkg"
"github.com/deckhouse/module-sdk/testing/framework"
subfolder "example-module/subfolder"
)
// TestHandlerHookPatch_AppliesPatchesToFakeCluster runs the patch hook
// inside the framework. After RunHook() the framework replays every
// recorded patch operation against its fake cluster, so we can assert on
// the resulting cluster state directly.
func TestHandlerHookPatch_AppliesPatchesToFakeCluster(t *testing.T) {
f := framework.HookExecutionConfigInit(t,
&pkg.HookConfig{OnBeforeHelm: &pkg.OrderedConfig{Order: 1}},
subfolder.HandlerHookPatch,
`{}`, `{}`,
)
f.RunHook()
require.NoError(t, f.HookError())
// The hook calls Create + Delete on my-first-pod, so it should be gone.
first := f.KubernetesResource("Pod", "default", "my-first-pod")
assert.Nil(t, first, "my-first-pod should have been deleted after Create+Delete")
// my-second-pod: CreateOrUpdate, then DeleteInBackground → also gone.
second := f.KubernetesResource("Pod", "default", "my-second-pod")
assert.Nil(t, second, "my-second-pod should have been deleted after Create+Delete")
// my-third-pod: CreateIfNotExists, then DeleteNonCascading → gone too,
// but not before being patched. Verify the hook recorded those calls.
ops := f.PatchedOperations()
require.Len(t, ops, 7)
var sawMerge bool
for _, op := range ops {
if op.Type == framework.PatchTypeMergePatch && op.Name == "my-third-pod" {
sawMerge = true
}
}
assert.True(t, sawMerge, "expected a MergePatch on my-third-pod")
}