From db488d7e93806eded860dee4a9bfe3a962f02953 Mon Sep 17 00:00:00 2001 From: myan Date: Thu, 13 Jun 2024 23:19:45 +0800 Subject: [PATCH] update the source client Signed-off-by: myan --- test/e2e/pkg/resources_test.go | 14 +++++++------- test/e2e/pkg/sourceclient_test.go | 13 ++++++------- test/e2e/pkg/suite_test.go | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/test/e2e/pkg/resources_test.go b/test/e2e/pkg/resources_test.go index 3acb1787..983c13aa 100644 --- a/test/e2e/pkg/resources_test.go +++ b/test/e2e/pkg/resources_test.go @@ -272,8 +272,8 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() { Context("Resource ReadOnly UpdateStrategy Tests via gRPC", func() { workName := "work-readonly-" + rand.String(5) secretName := "auth" - It("create a sample screct in the target cluster", func() { - _, err := kubeClient.CoreV1().Secrets("default").Create(context.Background(), &corev1.Secret{ + It("create a sample secret in the target cluster", func() { + _, err := consumer.ClientSet.CoreV1().Secrets("default").Create(ctx, &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ Name: secretName, Namespace: "default", @@ -299,7 +299,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() { objectStr, _ := obj.MarshalJSON() manifest := workv1.Manifest{} manifest.Raw = objectStr - _, err := workClient.ManifestWorks(consumer_name).Create(ctx, &workv1.ManifestWork{ + _, err := workClient.ManifestWorks(consumer.Name).Create(ctx, &workv1.ManifestWork{ ObjectMeta: metav1.ObjectMeta{ Name: workName, }, @@ -343,7 +343,7 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() { It("get the resource status back", func() { Eventually(func() error { - work, err := workClient.ManifestWorks(consumer_name).Get(ctx, workName, metav1.GetOptions{}) + work, err := workClient.ManifestWorks(consumer.Name).Get(ctx, workName, metav1.GetOptions{}) if err != nil { return err } @@ -362,14 +362,14 @@ var _ = Describe("Resources", Ordered, Label("e2e-tests-resources"), func() { }) It("delete the readonly resource", func() { - err := workClient.ManifestWorks(consumer_name).Delete(ctx, workName, metav1.DeleteOptions{}) + err := workClient.ManifestWorks(consumer.Name).Delete(ctx, workName, metav1.DeleteOptions{}) Expect(err).ShouldNot(HaveOccurred()) - err = kubeClient.CoreV1().Secrets("default").Delete(context.Background(), secretName, metav1.DeleteOptions{}) + err = consumer.ClientSet.CoreV1().Secrets("default").Delete(ctx, secretName, metav1.DeleteOptions{}) Expect(err).ShouldNot(HaveOccurred()) Eventually(func() error { - _, err := kubeClient.CoreV1().Secrets("default").Get(context.Background(), secretName, metav1.GetOptions{}) + _, err := consumer.ClientSet.CoreV1().Secrets("default").Get(ctx, secretName, metav1.GetOptions{}) if err != nil { if errors.IsNotFound(err) { return nil diff --git a/test/e2e/pkg/sourceclient_test.go b/test/e2e/pkg/sourceclient_test.go index 424cc141..892ab1d5 100644 --- a/test/e2e/pkg/sourceclient_test.go +++ b/test/e2e/pkg/sourceclient_test.go @@ -32,7 +32,7 @@ var _ = Describe("gRPC Source ManifestWork Client Test", func() { BeforeEach(func() { watchedWorks = []*workv1.ManifestWork{} - watcher, err := workClient.ManifestWorks(consumer_name).Watch(ctx, metav1.ListOptions{}) + watcher, err := workClient.ManifestWorks(consumer.Name).Watch(ctx, metav1.ListOptions{}) Expect(err).ShouldNot(HaveOccurred()) go func() { @@ -72,14 +72,14 @@ var _ = Describe("gRPC Source ManifestWork Client Test", func() { By("create a work") workName := "work-" + rand.String(5) - _, err = workClient.ManifestWorks(consumer_name).Create(ctx, NewManifestWork(workName), metav1.CreateOptions{}) + _, err = workClient.ManifestWorks(consumer.Name).Create(ctx, NewManifestWork(workName), metav1.CreateOptions{}) Expect(err).ShouldNot(HaveOccurred()) // wait for few seconds to ensure the creation is finished <-time.After(5 * time.Second) By("list the works") - works, err := workClient.ManifestWorks(consumer_name).List(ctx, metav1.ListOptions{}) + works, err := workClient.ManifestWorks(consumer.Name).List(ctx, metav1.ListOptions{}) Expect(err).ShouldNot(HaveOccurred()) Expect(len(works.Items) == 1).To(BeTrue()) @@ -87,21 +87,21 @@ var _ = Describe("gRPC Source ManifestWork Client Test", func() { <-time.After(5 * time.Second) By("update a work") - work, err := workClient.ManifestWorks(consumer_name).Get(ctx, workName, metav1.GetOptions{}) + work, err := workClient.ManifestWorks(consumer.Name).Get(ctx, workName, metav1.GetOptions{}) Expect(err).ShouldNot(HaveOccurred()) newWork := work.DeepCopy() newWork.Spec.Workload.Manifests = []workv1.Manifest{NewManifest(workName)} patchData, err := ToWorkPatch(work, newWork) Expect(err).ShouldNot(HaveOccurred()) - _, err = workClient.ManifestWorks(consumer_name).Patch(ctx, workName, types.MergePatchType, patchData, metav1.PatchOptions{}) + _, err = workClient.ManifestWorks(consumer.Name).Patch(ctx, workName, types.MergePatchType, patchData, metav1.PatchOptions{}) Expect(err).ShouldNot(HaveOccurred()) // wait for few seconds to ensure the work status is updated by agent <-time.After(5 * time.Second) By("delete a work") - err = workClient.ManifestWorks(consumer_name).Delete(ctx, workName, metav1.DeleteOptions{}) + err = workClient.ManifestWorks(consumer.Name).Delete(ctx, workName, metav1.DeleteOptions{}) Expect(err).ShouldNot(HaveOccurred()) Eventually(func() error { @@ -123,7 +123,6 @@ var _ = Describe("gRPC Source ManifestWork Client Test", func() { return nil }, 30*time.Second, 1*time.Second).ShouldNot(HaveOccurred()) - }) }) }) diff --git a/test/e2e/pkg/suite_test.go b/test/e2e/pkg/suite_test.go index f3df28f4..0c6a7a29 100644 --- a/test/e2e/pkg/suite_test.go +++ b/test/e2e/pkg/suite_test.go @@ -36,7 +36,6 @@ var ( cancel context.CancelFunc ctx context.Context sourceID string - cancel context.CancelFunc ) func TestE2E(t *testing.T) { @@ -88,6 +87,7 @@ var _ = BeforeSuite(func() { grpcOptions = grpc.NewGRPCOptions() grpcOptions.URL = grpcServerAddress + var err error workClient, err = work.NewClientHolderBuilder(grpcOptions). WithClientID(fmt.Sprintf("%s-watcher", sourceID)). WithSourceID(sourceID).