11package common_test
22
33import (
4+ "context"
45 "os"
56 "path/filepath"
67 "time"
@@ -9,21 +10,29 @@ import (
910 . "github.com/onsi/gomega"
1011 deploymentsv1alpha1 "github.com/pluralsh/deployment-operator/api/v1alpha1"
1112 "github.com/pluralsh/deployment-operator/pkg/common"
13+ testcommon "github.com/pluralsh/deployment-operator/pkg/test/common"
1214 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1315)
1416
1517var _ = Describe ("Health Test" , Ordered , func () {
1618 Context ("Test health functions" , func () {
1719 customResource := & deploymentsv1alpha1.MetricsAggregate {
1820 ObjectMeta : metav1.ObjectMeta {
19- Name : "test" ,
21+ Name : "test" ,
22+ Namespace : "default" ,
2023 },
2124 }
2225
26+ BeforeAll (func () {
27+ Expect (testcommon .MaybeCreate (kClient , customResource , nil )).To (Succeed ())
28+ })
29+
2330 It ("should get default status from CRD without condition block" , func () {
2431 obj , err := common .ToUnstructured (customResource )
32+ obj .SetKind ("MetricsAggregate" )
33+ obj .SetAPIVersion ("deployments.plural.sh/v1alpha1" )
2534 Expect (err ).NotTo (HaveOccurred ())
26- status , err := common .GetResourceHealth (obj )
35+ status , err := common .GetResourceHealth (context . Background (), kClient , obj )
2736 Expect (err ).NotTo (HaveOccurred ())
2837 Expect (status ).To (Not (BeNil ()))
2938 Expect (* status ).To (Equal (common.HealthStatus {
@@ -41,7 +50,9 @@ var _ = Describe("Health Test", Ordered, func() {
4150 }
4251 obj , err := common .ToUnstructured (customResource )
4352 Expect (err ).NotTo (HaveOccurred ())
44- status , err := common .GetResourceHealth (obj )
53+ obj .SetKind ("MetricsAggregate" )
54+ obj .SetAPIVersion ("deployments.plural.sh/v1alpha1" )
55+ status , err := common .GetResourceHealth (context .Background (), kClient , obj )
4556 Expect (err ).NotTo (HaveOccurred ())
4657 Expect (status ).To (Not (BeNil ()))
4758 Expect (* status ).To (Equal (common.HealthStatus {
@@ -61,7 +72,9 @@ var _ = Describe("Health Test", Ordered, func() {
6172 }
6273 obj , err := common .ToUnstructured (customResource )
6374 Expect (err ).NotTo (HaveOccurred ())
64- status , err := common .GetResourceHealth (obj )
75+ obj .SetKind ("MetricsAggregate" )
76+ obj .SetAPIVersion ("deployments.plural.sh/v1alpha1" )
77+ status , err := common .GetResourceHealth (context .Background (), kClient , obj )
6578 Expect (err ).NotTo (HaveOccurred ())
6679 Expect (status ).To (Not (BeNil ()))
6780 Expect (* status ).To (Equal (common.HealthStatus {
@@ -84,7 +97,7 @@ var _ = Describe("Health Test", Ordered, func() {
8497 obj .SetAPIVersion ("deployments.plural.sh/v1alpha1" )
8598 obj .SetKind ("MetricsAggregate" )
8699 Expect (err ).NotTo (HaveOccurred ())
87- status , err := common .GetResourceHealth (obj )
100+ status , err := common .GetResourceHealth (context . Background (), kClient , obj )
88101 Expect (err ).NotTo (HaveOccurred ())
89102 Expect (status ).To (Not (BeNil ()))
90103 Expect (* status ).To (Equal (common.HealthStatus {
@@ -98,7 +111,9 @@ var _ = Describe("Health Test", Ordered, func() {
98111 }
99112 obj , err := common .ToUnstructured (customResource )
100113 Expect (err ).NotTo (HaveOccurred ())
101- status , err := common .GetResourceHealth (obj )
114+ obj .SetKind ("MetricsAggregate" )
115+ obj .SetAPIVersion ("deployments.plural.sh/v1alpha1" )
116+ status , err := common .GetResourceHealth (context .Background (), kClient , obj )
102117 Expect (err ).NotTo (HaveOccurred ())
103118 Expect (status ).To (Not (BeNil ()))
104119 Expect (* status ).To (Equal (common.HealthStatus {
@@ -111,11 +126,13 @@ var _ = Describe("Health Test", Ordered, func() {
111126 customResource .DeletionTimestamp = nil
112127 obj , err := common .ToUnstructured (customResource )
113128 Expect (err ).NotTo (HaveOccurred ())
129+ obj .SetKind ("MetricsAggregate" )
130+ obj .SetAPIVersion ("deployments.plural.sh/v1alpha1" )
114131 scriptPath := filepath .Join (".." , ".." , "test" , "lua" , "test.lua" )
115132 script , err := os .ReadFile (scriptPath )
116133 Expect (err ).NotTo (HaveOccurred ())
117134 common .GetLuaScript ().SetValue (string (script ))
118- status , err := common .GetResourceHealth (obj )
135+ status , err := common .GetResourceHealth (context . Background (), kClient , obj )
119136 Expect (err ).NotTo (HaveOccurred ())
120137 Expect (status ).To (Not (BeNil ()))
121138 Expect (* status ).To (Equal (common.HealthStatus {
0 commit comments