11package common_test
22
33import (
4+ "os"
5+ "path/filepath"
46 "time"
57
68 . "github.com/onsi/ginkgo/v2"
79 . "github.com/onsi/gomega"
810 deploymentsv1alpha1 "github.com/pluralsh/deployment-operator/api/v1alpha1"
911 "github.com/pluralsh/deployment-operator/pkg/common"
1012 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11- "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
12- "k8s.io/apimachinery/pkg/runtime"
1313)
1414
1515var _ = Describe ("Health Test" , Ordered , func () {
@@ -21,9 +21,9 @@ var _ = Describe("Health Test", Ordered, func() {
2121 }
2222
2323 It ("should get default status from CRD without condition block" , func () {
24- obj , err := runtime . DefaultUnstructuredConverter .ToUnstructured (customResource )
24+ obj , err := common .ToUnstructured (customResource )
2525 Expect (err ).NotTo (HaveOccurred ())
26- status , err := common .GetResourceHealth (& unstructured. Unstructured { Object : obj } )
26+ status , err := common .GetResourceHealth (obj )
2727 Expect (err ).NotTo (HaveOccurred ())
2828 Expect (status ).To (Not (BeNil ()))
2929 Expect (* status ).To (Equal (common.HealthStatus {
@@ -39,9 +39,9 @@ var _ = Describe("Health Test", Ordered, func() {
3939 },
4040 },
4141 }
42- obj , err := runtime . DefaultUnstructuredConverter .ToUnstructured (customResource )
42+ obj , err := common .ToUnstructured (customResource )
4343 Expect (err ).NotTo (HaveOccurred ())
44- status , err := common .GetResourceHealth (& unstructured. Unstructured { Object : obj } )
44+ status , err := common .GetResourceHealth (obj )
4545 Expect (err ).NotTo (HaveOccurred ())
4646 Expect (status ).To (Not (BeNil ()))
4747 Expect (* status ).To (Equal (common.HealthStatus {
@@ -58,9 +58,9 @@ var _ = Describe("Health Test", Ordered, func() {
5858 },
5959 },
6060 }
61- obj , err := runtime . DefaultUnstructuredConverter .ToUnstructured (customResource )
61+ obj , err := common .ToUnstructured (customResource )
6262 Expect (err ).NotTo (HaveOccurred ())
63- status , err := common .GetResourceHealth (& unstructured. Unstructured { Object : obj } )
63+ status , err := common .GetResourceHealth (obj )
6464 Expect (err ).NotTo (HaveOccurred ())
6565 Expect (status ).To (Not (BeNil ()))
6666 Expect (* status ).To (Equal (common.HealthStatus {
@@ -72,9 +72,9 @@ var _ = Describe("Health Test", Ordered, func() {
7272 customResource .DeletionTimestamp = & metav1.Time {
7373 Time : time .Now (),
7474 }
75- obj , err := runtime . DefaultUnstructuredConverter .ToUnstructured (customResource )
75+ obj , err := common .ToUnstructured (customResource )
7676 Expect (err ).NotTo (HaveOccurred ())
77- status , err := common .GetResourceHealth (& unstructured. Unstructured { Object : obj } )
77+ status , err := common .GetResourceHealth (obj )
7878 Expect (err ).NotTo (HaveOccurred ())
7979 Expect (status ).To (Not (BeNil ()))
8080 Expect (* status ).To (Equal (common.HealthStatus {
@@ -83,5 +83,21 @@ var _ = Describe("Health Test", Ordered, func() {
8383 }))
8484 })
8585
86+ It ("should get status from Lua script" , func () {
87+ customResource .DeletionTimestamp = nil
88+ obj , err := common .ToUnstructured (customResource )
89+ Expect (err ).NotTo (HaveOccurred ())
90+ scriptPath := filepath .Join (".." , ".." , "test" , "lua" , "test.lua" )
91+ script , err := os .ReadFile (scriptPath )
92+ Expect (err ).NotTo (HaveOccurred ())
93+ common .GetLuaScript ().SetValue (string (script ))
94+ status , err := common .GetResourceHealth (obj )
95+ Expect (err ).NotTo (HaveOccurred ())
96+ Expect (status ).To (Not (BeNil ()))
97+ Expect (* status ).To (Equal (common.HealthStatus {
98+ Status : common .HealthStatusProgressing ,
99+ }))
100+ })
101+
86102 })
87103})
0 commit comments