|
| 1 | +/* |
| 2 | + |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package e2e |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + "os" |
| 22 | + "time" |
| 23 | + |
| 24 | + infrav1beta1 "github.com/cuisongliu/automq-operator/api/v1beta1" |
| 25 | + . "github.com/onsi/ginkgo/v2" |
| 26 | + . "github.com/onsi/gomega" |
| 27 | + v1 "k8s.io/api/core/v1" |
| 28 | + "k8s.io/apimachinery/pkg/api/errors" |
| 29 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 30 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 31 | +) |
| 32 | + |
| 33 | +var _ = Describe("automq_controller", func() { |
| 34 | + Context("automq_controller cr tests", func() { |
| 35 | + ctx := context.Background() |
| 36 | + namespaceName := "automq-operator" |
| 37 | + namespace := &v1.Namespace{ |
| 38 | + ObjectMeta: metav1.ObjectMeta{ |
| 39 | + Name: namespaceName, |
| 40 | + Namespace: namespaceName, |
| 41 | + }, |
| 42 | + } |
| 43 | + automq := &infrav1beta1.AutoMQ{} |
| 44 | + automq.Name = "automq-s1" |
| 45 | + automq.Namespace = namespaceName |
| 46 | + automq.Spec.ClusterID = "rZdE0DjZSrqy96PXrMUZVw" |
| 47 | + |
| 48 | + BeforeEach(func() { |
| 49 | + By("Creating the Namespace to perform the tests") |
| 50 | + err := k8sClient.Create(ctx, namespace) |
| 51 | + Expect(err).To(Not(HaveOccurred())) |
| 52 | + By("Setting the NAMESPACE_NAME ENV VAR which stores the Operand image") |
| 53 | + err = os.Setenv("NAMESPACE_NAME", namespaceName) |
| 54 | + Expect(err).To(Not(HaveOccurred())) |
| 55 | + }) |
| 56 | + It("Update Endpoint", func() { |
| 57 | + By("creating the custom resource for the automq") |
| 58 | + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(automq), automq) |
| 59 | + if err != nil && errors.IsNotFound(err) { |
| 60 | + // Let's mock our custom resource at the same way that we would |
| 61 | + // apply on the cluster the manifest under config/samples |
| 62 | + automq.Spec.S3.Endpoint = "http://minio.minio.svc.cluster.local:9000" |
| 63 | + automq.Spec.S3.Bucket = "ko3" |
| 64 | + automq.Spec.S3.AccessKeyID = "admin" |
| 65 | + automq.Spec.S3.SecretAccessKey = "minio123" |
| 66 | + automq.Spec.S3.Region = "us-east-1" |
| 67 | + automq.Spec.S3.EnablePathStyle = true |
| 68 | + automq.Spec.Controller.Replicas = 1 |
| 69 | + automq.Spec.Broker.Replicas = 3 |
| 70 | + automq.Spec.NodePort = 32009 |
| 71 | + err = k8sClient.Create(ctx, automq) |
| 72 | + Expect(err).To(Not(HaveOccurred())) |
| 73 | + } |
| 74 | + }) |
| 75 | + AfterEach(func() { |
| 76 | + By("removing the custom resource for the automq") |
| 77 | + found := &infrav1beta1.AutoMQ{} |
| 78 | + err := k8sClient.Get(ctx, client.ObjectKeyFromObject(automq), found) |
| 79 | + Expect(err).To(Not(HaveOccurred())) |
| 80 | + |
| 81 | + Eventually(func() error { |
| 82 | + return k8sClient.Delete(context.TODO(), found) |
| 83 | + }, 2*time.Minute, time.Second).Should(Succeed()) |
| 84 | + |
| 85 | + // TODO(user): Attention if you improve this code by adding other context test you MUST |
| 86 | + // be aware of the current delete namespace limitations. |
| 87 | + // More info: https://book.kubebuilder.io/reference/envtest.html#testing-considerations |
| 88 | + By("Deleting the Namespace to perform the tests") |
| 89 | + _ = k8sClient.Delete(ctx, namespace) |
| 90 | + |
| 91 | + By("Removing the Image ENV VAR which stores the Operand image") |
| 92 | + _ = os.Unsetenv("NAMESPACE_NAME") |
| 93 | + }) |
| 94 | + }) |
| 95 | + |
| 96 | +}) |
0 commit comments