forked from opendatahub-io/odh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkueue_test.go
More file actions
155 lines (126 loc) · 5.09 KB
/
kueue_test.go
File metadata and controls
155 lines (126 loc) · 5.09 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package kueue_test
import (
"testing"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"github.com/opendatahub-io/odh-cli/pkg/lint/check"
resultpkg "github.com/opendatahub-io/odh-cli/pkg/lint/check/result"
"github.com/opendatahub-io/odh-cli/pkg/lint/check/testutil"
"github.com/opendatahub-io/odh-cli/pkg/lint/checks/components/kueue"
"github.com/opendatahub-io/odh-cli/pkg/resources"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"
)
//nolint:gochecknoglobals // Test fixture - shared across test functions
var listKinds = map[schema.GroupVersionResource]string{
resources.DataScienceCluster.GVR(): resources.DataScienceCluster.ListKind(),
}
func TestManagementStateCheck_CanApply_NoDSC(t *testing.T) {
g := NewWithT(t)
target := testutil.NewTarget(t, testutil.TargetConfig{
ListKinds: listKinds,
CurrentVersion: "2.17.0",
TargetVersion: "3.0.0",
})
chk := kueue.NewManagementStateCheck()
canApply, err := chk.CanApply(t.Context(), target)
g.Expect(err).To(HaveOccurred())
g.Expect(canApply).To(BeFalse())
}
func TestManagementStateCheck_CanApply_NotConfigured(t *testing.T) {
g := NewWithT(t)
// DSC without kueue component — state defaults to empty, not Managed/Unmanaged
dsc := testutil.NewDSC(map[string]string{"dashboard": "Managed"})
target := testutil.NewTarget(t, testutil.TargetConfig{
ListKinds: listKinds,
Objects: []*unstructured.Unstructured{dsc},
CurrentVersion: "2.17.0",
TargetVersion: "3.0.0",
})
chk := kueue.NewManagementStateCheck()
canApply, err := chk.CanApply(t.Context(), target)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(canApply).To(BeFalse())
}
func TestManagementStateCheck_ManagedProhibited(t *testing.T) {
g := NewWithT(t)
ctx := t.Context()
target := testutil.NewTarget(t, testutil.TargetConfig{
ListKinds: listKinds,
Objects: []*unstructured.Unstructured{testutil.NewDSC(map[string]string{"kueue": "Managed"})},
CurrentVersion: "2.17.0",
TargetVersion: "3.0.0",
})
chk := kueue.NewManagementStateCheck()
result, err := chk.Validate(ctx, target)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(result.Status.Conditions).To(HaveLen(1))
g.Expect(result.Status.Conditions[0].Condition).To(MatchFields(IgnoreExtras, Fields{
"Type": Equal(check.ConditionTypeCompatible),
"Status": Equal(metav1.ConditionFalse),
"Reason": Equal(check.ReasonVersionIncompatible),
"Message": And(ContainSubstring("only supports the Kueue managementState of Removed"), ContainSubstring("migrated to the Red Hat build of Kueue Operator")),
}))
g.Expect(result.Status.Conditions[0].Impact).To(Equal(resultpkg.ImpactProhibited))
g.Expect(result.Annotations).To(And(
HaveKeyWithValue("component.opendatahub.io/management-state", "Managed"),
HaveKeyWithValue("check.opendatahub.io/target-version", "3.0.0"),
))
}
func TestManagementStateCheck_UnmanagedProhibited(t *testing.T) {
g := NewWithT(t)
ctx := t.Context()
target := testutil.NewTarget(t, testutil.TargetConfig{
ListKinds: listKinds,
Objects: []*unstructured.Unstructured{testutil.NewDSC(map[string]string{"kueue": "Unmanaged"})},
CurrentVersion: "2.17.0",
TargetVersion: "3.1.0",
})
chk := kueue.NewManagementStateCheck()
result, err := chk.Validate(ctx, target)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(result.Status.Conditions).To(HaveLen(1))
g.Expect(result.Status.Conditions[0].Condition).To(MatchFields(IgnoreExtras, Fields{
"Type": Equal(check.ConditionTypeCompatible),
"Status": Equal(metav1.ConditionFalse),
"Reason": Equal(check.ReasonVersionIncompatible),
"Message": And(ContainSubstring("only supports the Kueue managementState of Removed"), Not(ContainSubstring("migrated to the Red Hat build of Kueue Operator"))),
}))
g.Expect(result.Status.Conditions[0].Impact).To(Equal(resultpkg.ImpactProhibited))
}
func TestManagementStateCheck_CanApply_ManagementState(t *testing.T) {
g := NewWithT(t)
chk := kueue.NewManagementStateCheck()
testCases := []struct {
name string
state string
expected bool
}{
{name: "Managed", state: "Managed", expected: true},
{name: "Unmanaged", state: "Unmanaged", expected: true},
{name: "Removed", state: "Removed", expected: false},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
dsc := testutil.NewDSC(map[string]string{"kueue": tc.state})
target := testutil.NewTarget(t, testutil.TargetConfig{
ListKinds: listKinds,
Objects: []*unstructured.Unstructured{dsc},
CurrentVersion: "2.17.0",
TargetVersion: "3.0.0",
})
canApply, err := chk.CanApply(t.Context(), target)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(canApply).To(Equal(tc.expected))
})
}
}
func TestManagementStateCheck_Metadata(t *testing.T) {
g := NewWithT(t)
chk := kueue.NewManagementStateCheck()
g.Expect(chk.ID()).To(Equal("components.kueue.management-state"))
g.Expect(chk.Name()).To(Equal("Components :: Kueue :: Management State (3.x)"))
g.Expect(chk.Group()).To(Equal(check.GroupComponent))
g.Expect(chk.Description()).ToNot(BeEmpty())
}