-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgetOvercommitClass_test.go
More file actions
90 lines (76 loc) · 2.91 KB
/
getOvercommitClass_test.go
File metadata and controls
90 lines (76 loc) · 2.91 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
// SPDX-FileCopyrightText: 2025 2025 INDUSTRIA DE DISEÑO TEXTIL S.A. (INDITEX S.A.)
// SPDX-FileContributor: enriqueavi@inditex.com
//
// SPDX-License-Identifier: Apache-2.0
package utils
import (
"context"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
overcommit "github.com/InditexTech/k8s-overcommit-operator/api/v1alphav1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
var _ = Describe("GetOvercommitClassSpec", func() {
var overcommitClass *overcommit.OvercommitClass
BeforeEach(func() {
// Create a test OvercommitClass with IsDefault: false
overcommitClass = &overcommit.OvercommitClass{
ObjectMeta: metav1.ObjectMeta{
Name: "test-overcommitclass",
},
Spec: overcommit.OvercommitClassSpec{
CpuOvercommit: 0.5,
MemoryOvercommit: 0.5,
ExcludedNamespaces: "kube-system",
IsDefault: false,
},
}
// Create the resource in the test cluster
err := k8sClient.Create(context.Background(), overcommitClass)
Expect(err).NotTo(HaveOccurred(), "Failed to create OvercommitClass")
})
AfterEach(func() {
// Delete the resource after each test
err := k8sClient.Delete(context.Background(), overcommitClass)
Expect(err).NotTo(HaveOccurred(), "Failed to delete OvercommitClass")
})
It("should retrieve the OvercommitClassSpec correctly", func() {
// Try the GetOvercommitClassSpec function
spec, err := GetOvercommitClassSpec(context.TODO(), "test-overcommitclass", k8sClient)
Expect(err).NotTo(HaveOccurred(), "Failed to get OvercommitClassSpec")
Expect(spec).NotTo(BeNil(), "Spec should not be nil")
Expect(spec).To(Equal(&overcommitClass.Spec), "Spec should match the created OvercommitClass")
})
})
var _ = Describe("GetDefaultSpec", func() {
var overcommitClass *overcommit.OvercommitClass
BeforeEach(func() {
// Create a test OvercommitClass with IsDefault: true
overcommitClass = &overcommit.OvercommitClass{
ObjectMeta: metav1.ObjectMeta{
Name: "test-default-overcommitclass",
},
Spec: overcommit.OvercommitClassSpec{
CpuOvercommit: 0.5,
MemoryOvercommit: 0.5,
ExcludedNamespaces: "kube-system",
IsDefault: true,
},
}
// Create the resource in the test cluster
err := k8sClient.Create(context.Background(), overcommitClass)
Expect(err).NotTo(HaveOccurred(), "Failed to create default OvercommitClass")
})
AfterEach(func() {
// Delete the resource after each test
err := k8sClient.Delete(context.Background(), overcommitClass)
Expect(err).NotTo(HaveOccurred(), "Failed to delete default OvercommitClass")
})
It("should retrieve the default OvercommitClassSpec correctly", func() {
// Try the GetDefaultSpec function
spec, err := GetDefaultSpec(context.Background(), k8sClient)
Expect(err).NotTo(HaveOccurred(), "Failed to get default OvercommitClassSpec")
Expect(spec).NotTo(BeNil(), "Spec should not be nil")
Expect(spec.IsDefault).To(BeTrue(), "Spec.IsDefault should be true")
})
})