Skip to content

Commit

Permalink
fix: e2e and conflict after rebase
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriele Quaresima <[email protected]>
  • Loading branch information
gabriele-wolfox committed Oct 14, 2024
1 parent 82c0177 commit 98dfb5d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 66 deletions.
4 changes: 2 additions & 2 deletions internal/cmd/manager/instance/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func runSubCommand(ctx context.Context, instance *postgres.Instance) error {
For(&apiv1.Publication{}).
Complete(publicationReconciler)
if err != nil {
setupLog.Error(err, "unable to create publication controller")
contextLogger.Error(err, "unable to create publication controller")
return err
}

Expand All @@ -241,7 +241,7 @@ func runSubCommand(ctx context.Context, instance *postgres.Instance) error {
For(&apiv1.Subscription{}).
Complete(subscriptionReconciler)
if err != nil {
setupLog.Error(err, "unable to create subscription controller")
contextLogger.Error(err, "unable to create subscription controller")
return err
}

Expand Down
110 changes: 46 additions & 64 deletions tests/e2e/declarative_pub_sub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,6 @@ var _ = Describe("Declarative publication and subscription test", Label(tests.La
})
})

assertDatabaseExists := func(namespace, primaryPod, dbname string) {
Eventually(func(g Gomega) {
stdout, _, err := env.ExecQueryInInstancePod(
utils.PodLocator{
Namespace: namespace,
PodName: primaryPod,
},
"postgres",
"\\l")
g.Expect(err).ToNot(HaveOccurred())
g.Expect(stdout).Should(ContainSubstring(dbname))
}, 300).Should(Succeed())
}

assertPublicationExists := func(namespace, primaryPod string, pub *apiv1.Publication) {
query := fmt.Sprintf("select count(*) from pg_publication where pubname = '%s'",
pub.Spec.Name)
Expand Down Expand Up @@ -132,7 +118,7 @@ var _ = Describe("Declarative publication and subscription test", Label(tests.La
}, 30).Should(Succeed())
}

It("can add a declarative database", func() { //nolint:dupl
It("can add a declarative database, publication and subscription", func() { //nolint:dupl
By("applying Database CRD manifest", func() {
CreateResourceFromFile(namespace, databaseManifest)
databaseObjectName, err = env.GetResourceNameFromYAML(databaseManifest)
Expand All @@ -157,64 +143,60 @@ var _ = Describe("Declarative publication and subscription test", Label(tests.La
primaryPodInfo, err := env.GetClusterPrimary(namespace, sourceClusterName)
Expect(err).ToNot(HaveOccurred())

assertDatabaseExists(namespace, primaryPodInfo.Name, dbname)
AssertDatabaseExists(namespace, primaryPodInfo.Name, dbname, true)
})
})
It("can add a declarative publication", func() { //nolint:dupl
By("applying Publication CRD manifest", func() {
CreateResourceFromFile(namespace, pubManifest)
pubObjectName, err = env.GetResourceNameFromYAML(pubManifest)
Expect(err).NotTo(HaveOccurred())
})
By("ensuring the Publication CRD succeeded reconciliation", func() {
// get publication object
pub = &apiv1.Publication{}
pubNamespacedName := types.NamespacedName{
Namespace: namespace,
Name: pubObjectName,
}

Eventually(func(g Gomega) {
err := env.Client.Get(env.Ctx, pubNamespacedName, pub)
Expect(err).ToNot(HaveOccurred())
g.Expect(pub.Status.Ready).Should(BeTrue())
}, 300).WithPolling(10 * time.Second).Should(Succeed())
})
By("applying Publication CRD manifest", func() {
CreateResourceFromFile(namespace, pubManifest)
pubObjectName, err = env.GetResourceNameFromYAML(pubManifest)
Expect(err).NotTo(HaveOccurred())
})
By("ensuring the Publication CRD succeeded reconciliation", func() {
// get publication object
pub = &apiv1.Publication{}
pubNamespacedName := types.NamespacedName{
Namespace: namespace,
Name: pubObjectName,
}

By("verifying new publication has been created", func() {
primaryPodInfo, err := env.GetClusterPrimary(namespace, sourceClusterName)
Eventually(func(g Gomega) {
err := env.Client.Get(env.Ctx, pubNamespacedName, pub)
Expect(err).ToNot(HaveOccurred())

assertPublicationExists(namespace, primaryPodInfo.Name, pub)
})
g.Expect(pub.Status.Ready).Should(BeTrue())
}, 300).WithPolling(10 * time.Second).Should(Succeed())
})
It("can add a declarative subscription", func() { //nolint:dupl
By("applying Subscription CRD manifest", func() {
CreateResourceFromFile(namespace, subManifest)
subObjectName, err = env.GetResourceNameFromYAML(subManifest)
Expect(err).NotTo(HaveOccurred())
})
By("ensuring the Subscription CRD succeeded reconciliation", func() {
// get subscription object
sub = &apiv1.Subscription{}
pubNamespacedName := types.NamespacedName{
Namespace: namespace,
Name: subObjectName,
}

Eventually(func(g Gomega) {
err := env.Client.Get(env.Ctx, pubNamespacedName, sub)
Expect(err).ToNot(HaveOccurred())
g.Expect(sub.Status.Ready).Should(BeTrue())
}, 300).WithPolling(10 * time.Second).Should(Succeed())
})
By("verifying new publication has been created", func() {
primaryPodInfo, err := env.GetClusterPrimary(namespace, sourceClusterName)
Expect(err).ToNot(HaveOccurred())

assertPublicationExists(namespace, primaryPodInfo.Name, pub)
})
By("applying Subscription CRD manifest", func() {
CreateResourceFromFile(namespace, subManifest)
subObjectName, err = env.GetResourceNameFromYAML(subManifest)
Expect(err).NotTo(HaveOccurred())
})
By("ensuring the Subscription CRD succeeded reconciliation", func() {
// get subscription object
sub = &apiv1.Subscription{}
pubNamespacedName := types.NamespacedName{
Namespace: namespace,
Name: subObjectName,
}

By("verifying new subscription has been created", func() {
primaryPodInfo, err := env.GetClusterPrimary(namespace, destinationClusterName)
Eventually(func(g Gomega) {
err := env.Client.Get(env.Ctx, pubNamespacedName, sub)
Expect(err).ToNot(HaveOccurred())
g.Expect(sub.Status.Ready).Should(BeTrue())
}, 300).WithPolling(10 * time.Second).Should(Succeed())
})

assertSubscriptionExists(namespace, primaryPodInfo.Name, sub)
})
By("verifying new subscription has been created", func() {
primaryPodInfo, err := env.GetClusterPrimary(namespace, destinationClusterName)
Expect(err).ToNot(HaveOccurred())

assertSubscriptionExists(namespace, primaryPodInfo.Name, sub)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ metadata:
name: destination-cluster
spec:
instances: 3
externalClusters:
- source-cluster

postgresql:
parameters:
Expand Down

0 comments on commit 98dfb5d

Please sign in to comment.