MCPcopy
hub / github.com/fluid-cloudnative/fluid / TestCheckWorkerAffinity

Function TestCheckWorkerAffinity

pkg/ctrl/ctrl_test.go:33–216  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31)
32
33func TestCheckWorkerAffinity(t *testing.T) {
34
35 s := runtime.NewScheme()
36 name := "check-worker-affinity"
37 namespace := "big-data"
38 runtimeObjs := []runtime.Object{}
39 mockClient := fake.NewFakeClientWithScheme(s, runtimeObjs...)
40 runtimeInfo, err := base.BuildRuntimeInfo(name, namespace, common.JindoRuntime)
41 if err != nil {
42 t.Errorf("testcase %s failed due to %v", name, err)
43 }
44 h := BuildHelper(runtimeInfo, mockClient, fake.NullLogger())
45
46 tests := []struct {
47 name string
48 worker *appsv1.StatefulSet
49 want bool
50 }{
51 {
52 name: "no affinity",
53 worker: &appsv1.StatefulSet{
54 ObjectMeta: metav1.ObjectMeta{
55 Name: "no-affinity-worker",
56 Namespace: namespace,
57 },
58 Spec: appsv1.StatefulSetSpec{
59 Replicas: ptr.To[int32](1),
60 },
61 },
62 want: false,
63 }, {
64 name: "no node affinity",
65 worker: &appsv1.StatefulSet{
66 ObjectMeta: metav1.ObjectMeta{
67 Name: "no-node-affinity-worker",
68 Namespace: namespace,
69 },
70 Spec: appsv1.StatefulSetSpec{
71 Replicas: ptr.To[int32](1),
72 Template: v1.PodTemplateSpec{
73 Spec: v1.PodSpec{
74 Affinity: &v1.Affinity{}}},
75 },
76 },
77 want: false,
78 }, {
79 name: "other affinity exists",
80 worker: &appsv1.StatefulSet{
81 ObjectMeta: metav1.ObjectMeta{
82 Name: name + "-worker",
83 Namespace: namespace,
84 },
85 Spec: appsv1.StatefulSetSpec{
86 Replicas: ptr.To[int32](1),
87 Template: v1.PodTemplateSpec{
88 Spec: v1.PodSpec{
89 Affinity: &v1.Affinity{
90 PodAntiAffinity: &v1.PodAntiAffinity{

Callers

nothing calls this directly

Calls 5

NewFakeClientWithSchemeFunction · 0.92
BuildRuntimeInfoFunction · 0.92
NullLoggerFunction · 0.92
BuildHelperFunction · 0.85
checkWorkerAffinityMethod · 0.80

Tested by

no test coverage detected