Skip to content

Commit df1ed6c

Browse files
authored
Merge pull request #2861 from NikhilSharmaWe/testStatusCond
✨deploy-image/v1-alpha: add check for status conditions added to the custom resource
2 parents dd7d3db + 8064de1 commit df1ed6c

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"
@@ -162,6 +163,20 @@ var _ = Describe("{{ .Resource.Kind }} controller", func() {
162163
found := &appsv1.Deployment{}
163164
return k8sClient.Get(ctx, typeNamespaceName, found)
164165
}, time.Minute, time.Second).Should(Succeed())
166+
167+
By("Checking the latest Status Condition added to the {{ .Resource.Kind }} instance")
168+
Eventually(func() error {
169+
if {{ lower .Resource.Kind }}.Status.Conditions != nil && len({{ lower .Resource.Kind }}.Status.Conditions) != 0 {
170+
latestStatusCondition := {{ lower .Resource.Kind }}.Status.Conditions[len({{ lower .Resource.Kind }}.Status.Conditions)-1]
171+
expectedLatestStatusCondition := metav1.Condition{Type: typeAvailable{{ .Resource.Kind }},
172+
Status: metav1.ConditionTrue, Reason: "Reconciling",
173+
Message: fmt.Sprintf("Deployment for custom resource (%s) with %d replicas created successfully", {{ lower .Resource.Kind }}.Name, {{ lower .Resource.Kind }}.Spec.Size)}
174+
if latestStatusCondition != expectedLatestStatusCondition {
175+
return fmt.Errorf("The latest status condition added to the {{ lower .Resource.Kind }} instance is not as expected")
176+
}
177+
}
178+
return nil
179+
}, time.Minute, time.Second).Should(Succeed())
165180
})
166181
})
167182
})

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)