bluegreen_controller_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package controllers
  2. import (
  3. "time"
  4. v1 "github.com/kakao/bluegreen/api/v1"
  5. . "github.com/onsi/ginkgo"
  6. . "github.com/onsi/gomega"
  7. corev1 "k8s.io/api/core/v1"
  8. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  9. )
  10. var _ = Describe("BlueGreen controller", func() {
  11. const (
  12. timeout = time.Second * 10
  13. duration = time.Second * 10
  14. interval = time.Millisecond * 250
  15. )
  16. Context("When creating a New BlueGreen Resource", func() {
  17. Context("When defining Blue Spec only", func() {
  18. It("Should Create a One Service and a One Deployment", func() {
  19. Expect(
  20. k8sClient.Create(ctx,
  21. &v1.BlueGreen{
  22. ObjectMeta: metav1.ObjectMeta{
  23. Name: "bluegreen-test",
  24. Namespace: "default",
  25. },
  26. Spec: v1.BlueGreenSpec{
  27. RouteTo: v1.Blue,
  28. BlueSpec: &corev1.PodSpec{
  29. Containers: []corev1.Container{
  30. {Name: "blue", Image: "nginx"},
  31. },
  32. },
  33. },
  34. },
  35. ),
  36. ).Should(Succeed())
  37. svcList := &corev1.ServiceList{}
  38. Eventually(func() bool {
  39. if err := k8sClient.List(ctx, svcList); err != nil {
  40. return false
  41. }
  42. return len(svcList.Items) != 0
  43. }, timeout, interval).Should(BeTrue())
  44. Expect(len(svcList.Items)).To(Equal(1))
  45. /* More Validation Logics here */
  46. })
  47. })
  48. /* More Test Scenarios here */
  49. })
  50. })