Skip to content

Commit 8064de1

Browse files
add check for status conditions added to the custom resource
1 parent 7cd3532 commit 8064de1

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed

pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import (
6363
"context"
6464
"os"
6565
"time"
66+
"fmt"
6667
6768
. "github.com/onsi/ginkgo"
6869
. "github.com/onsi/gomega"
@@ -160,6 +161,20 @@ var _ = Describe("{{ .Resource.Kind }} controller", func() {
160161
found := &appsv1.Deployment{}
161162
return k8sClient.Get(ctx, typeNamespaceName, found)
162163
}, time.Minute, time.Second).Should(Succeed())
164+
165+
By("Checking the latest Status Condition added to the {{ .Resource.Kind }} instance")
166+
Eventually(func() error {
167+
if {{ lower .Resource.Kind }}.Status.Conditions != nil && len({{ lower .Resource.Kind }}.Status.Conditions) != 0 {
168+
latestStatusCondition := {{ lower .Resource.Kind }}.Status.Conditions[len({{ lower .Resource.Kind }}.Status.Conditions)-1]
169+
expectedLatestStatusCondition := metav1.Condition{Type: typeAvailable{{ .Resource.Kind }},
170+
Status: metav1.ConditionTrue, Reason: "Reconciling",
171+
Message: fmt.Sprintf("Deployment for custom resource (%s) with %d replicas created successfully", {{ lower .Resource.Kind }}.Name, {{ lower .Resource.Kind }}.Spec.Size)}
172+
if latestStatusCondition != expectedLatestStatusCondition {
173+
return fmt.Errorf("The latest status condition added to the {{ lower .Resource.Kind }} instance is not as expected")
174+
}
175+
}
176+
return nil
177+
}, time.Minute, time.Second).Should(Succeed())
163178
})
164179
})
165180
})

testdata/project-v3-with-deploy-image/controllers/busybox_controller_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package controllers
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"os"
2223
"time"
2324

@@ -110,6 +111,20 @@ var _ = Describe("Busybox controller", func() {
110111
found := &appsv1.Deployment{}
111112
return k8sClient.Get(ctx, typeNamespaceName, found)
112113
}, time.Minute, time.Second).Should(Succeed())
114+
115+
By("Checking the latest Status Condition added to the Busybox instance")
116+
Eventually(func() error {
117+
if busybox.Status.Conditions != nil && len(busybox.Status.Conditions) != 0 {
118+
latestStatusCondition := busybox.Status.Conditions[len(busybox.Status.Conditions)-1]
119+
expectedLatestStatusCondition := metav1.Condition{Type: typeAvailableBusybox,
120+
Status: metav1.ConditionTrue, Reason: "Reconciling",
121+
Message: fmt.Sprintf("Deployment for custom resource (%s) with %d replicas created successfully", busybox.Name, busybox.Spec.Size)}
122+
if latestStatusCondition != expectedLatestStatusCondition {
123+
return fmt.Errorf("The latest status condition added to the busybox instance is not as expected")
124+
}
125+
}
126+
return nil
127+
}, time.Minute, time.Second).Should(Succeed())
113128
})
114129
})
115130
})

testdata/project-v3-with-deploy-image/controllers/memcached_controller_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package controllers
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"os"
2223
"time"
2324

@@ -111,6 +112,20 @@ var _ = Describe("Memcached controller", func() {
111112
found := &appsv1.Deployment{}
112113
return k8sClient.Get(ctx, typeNamespaceName, found)
113114
}, time.Minute, time.Second).Should(Succeed())
115+
116+
By("Checking the latest Status Condition added to the Memcached instance")
117+
Eventually(func() error {
118+
if memcached.Status.Conditions != nil && len(memcached.Status.Conditions) != 0 {
119+
latestStatusCondition := memcached.Status.Conditions[len(memcached.Status.Conditions)-1]
120+
expectedLatestStatusCondition := metav1.Condition{Type: typeAvailableMemcached,
121+
Status: metav1.ConditionTrue, Reason: "Reconciling",
122+
Message: fmt.Sprintf("Deployment for custom resource (%s) with %d replicas created successfully", memcached.Name, memcached.Spec.Size)}
123+
if latestStatusCondition != expectedLatestStatusCondition {
124+
return fmt.Errorf("The latest status condition added to the memcached instance is not as expected")
125+
}
126+
}
127+
return nil
128+
}, time.Minute, time.Second).Should(Succeed())
114129
})
115130
})
116131
})

testdata/project-v4-with-deploy-image/controllers/busybox_controller_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package controllers
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"os"
2223
"time"
2324

@@ -110,6 +111,20 @@ var _ = Describe("Busybox controller", func() {
110111
found := &appsv1.Deployment{}
111112
return k8sClient.Get(ctx, typeNamespaceName, found)
112113
}, time.Minute, time.Second).Should(Succeed())
114+
115+
By("Checking the latest Status Condition added to the Busybox instance")
116+
Eventually(func() error {
117+
if busybox.Status.Conditions != nil && len(busybox.Status.Conditions) != 0 {
118+
latestStatusCondition := busybox.Status.Conditions[len(busybox.Status.Conditions)-1]
119+
expectedLatestStatusCondition := metav1.Condition{Type: typeAvailableBusybox,
120+
Status: metav1.ConditionTrue, Reason: "Reconciling",
121+
Message: fmt.Sprintf("Deployment for custom resource (%s) with %d replicas created successfully", busybox.Name, busybox.Spec.Size)}
122+
if latestStatusCondition != expectedLatestStatusCondition {
123+
return fmt.Errorf("The latest status condition added to the busybox instance is not as expected")
124+
}
125+
}
126+
return nil
127+
}, time.Minute, time.Second).Should(Succeed())
113128
})
114129
})
115130
})

testdata/project-v4-with-deploy-image/controllers/memcached_controller_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package controllers
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"os"
2223
"time"
2324

@@ -111,6 +112,20 @@ var _ = Describe("Memcached controller", func() {
111112
found := &appsv1.Deployment{}
112113
return k8sClient.Get(ctx, typeNamespaceName, found)
113114
}, time.Minute, time.Second).Should(Succeed())
115+
116+
By("Checking the latest Status Condition added to the Memcached instance")
117+
Eventually(func() error {
118+
if memcached.Status.Conditions != nil && len(memcached.Status.Conditions) != 0 {
119+
latestStatusCondition := memcached.Status.Conditions[len(memcached.Status.Conditions)-1]
120+
expectedLatestStatusCondition := metav1.Condition{Type: typeAvailableMemcached,
121+
Status: metav1.ConditionTrue, Reason: "Reconciling",
122+
Message: fmt.Sprintf("Deployment for custom resource (%s) with %d replicas created successfully", memcached.Name, memcached.Spec.Size)}
123+
if latestStatusCondition != expectedLatestStatusCondition {
124+
return fmt.Errorf("The latest status condition added to the memcached instance is not as expected")
125+
}
126+
}
127+
return nil
128+
}, time.Minute, time.Second).Should(Succeed())
114129
})
115130
})
116131
})

0 commit comments

Comments
 (0)