mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-07-06 17:52:21 +02:00
test: cover NewFromCluster replica-source derivation
Add config-package tests exercising the parse path the pg_basebackup replica fix lives in: NewFromCluster must derive ReplicaSourceBarmanObjectName from the external cluster plugin (while leaving the backup and recovery object stores empty) and Validate must accept it. Also assert that a replica source backed by a different plugin is ignored. Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
This commit is contained in:
parent
8b48609a82
commit
8fbcedbbc8
@ -20,8 +20,13 @@ SPDX-License-Identifier: Apache-2.0
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
|
"github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/metadata"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("PluginConfiguration.Validate", func() {
|
var _ = Describe("PluginConfiguration.Validate", func() {
|
||||||
@ -45,3 +50,77 @@ var _ = Describe("PluginConfiguration.Validate", func() {
|
|||||||
Expect(cfg.Validate()).To(Succeed())
|
Expect(cfg.Validate()).To(Succeed())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var _ = Describe("NewFromCluster", func() {
|
||||||
|
enabled := true
|
||||||
|
|
||||||
|
It("derives the replica source object store for a pg_basebackup replica cluster", func() {
|
||||||
|
cluster := &cnpgv1.Cluster{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: "cluster-replica", Namespace: "test-ns"},
|
||||||
|
Spec: cnpgv1.ClusterSpec{
|
||||||
|
Bootstrap: &cnpgv1.BootstrapConfiguration{
|
||||||
|
PgBaseBackup: &cnpgv1.BootstrapPgBaseBackup{Source: "source"},
|
||||||
|
},
|
||||||
|
ReplicaCluster: &cnpgv1.ReplicaClusterConfiguration{
|
||||||
|
Enabled: &enabled,
|
||||||
|
Source: "source",
|
||||||
|
},
|
||||||
|
ExternalClusters: []cnpgv1.ExternalCluster{
|
||||||
|
{
|
||||||
|
Name: "source",
|
||||||
|
PluginConfiguration: &cnpgv1.PluginConfiguration{
|
||||||
|
Name: metadata.PluginName,
|
||||||
|
Parameters: map[string]string{
|
||||||
|
"barmanObjectName": "minio-store",
|
||||||
|
"serverName": "cluster-example",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg := NewFromCluster(cluster)
|
||||||
|
|
||||||
|
// The replica source object store is derived from the external cluster plugin,
|
||||||
|
// while the backup/archive and recovery object stores remain empty: this is the
|
||||||
|
// distinguishing trait of a pg_basebackup replica cluster (a recovery-bootstrapped
|
||||||
|
// replica would also populate RecoveryBarmanObjectName).
|
||||||
|
Expect(cfg.ReplicaSourceBarmanObjectName).To(Equal("minio-store"))
|
||||||
|
Expect(cfg.ReplicaSourceServerName).To(Equal("cluster-example"))
|
||||||
|
Expect(cfg.BarmanObjectName).To(BeEmpty())
|
||||||
|
Expect(cfg.RecoveryBarmanObjectName).To(BeEmpty())
|
||||||
|
|
||||||
|
// Validate must accept it, otherwise the lifecycle hook skips sidecar injection.
|
||||||
|
Expect(cfg.Validate()).To(Succeed())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("ignores a replica source backed by a different plugin", func() {
|
||||||
|
cluster := &cnpgv1.Cluster{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: "cluster-replica", Namespace: "test-ns"},
|
||||||
|
Spec: cnpgv1.ClusterSpec{
|
||||||
|
Bootstrap: &cnpgv1.BootstrapConfiguration{
|
||||||
|
PgBaseBackup: &cnpgv1.BootstrapPgBaseBackup{Source: "source"},
|
||||||
|
},
|
||||||
|
ReplicaCluster: &cnpgv1.ReplicaClusterConfiguration{
|
||||||
|
Enabled: &enabled,
|
||||||
|
Source: "source",
|
||||||
|
},
|
||||||
|
ExternalClusters: []cnpgv1.ExternalCluster{
|
||||||
|
{
|
||||||
|
Name: "source",
|
||||||
|
PluginConfiguration: &cnpgv1.PluginConfiguration{
|
||||||
|
Name: "some-other-plugin.cloudnative-pg.io",
|
||||||
|
Parameters: map[string]string{"barmanObjectName": "minio-store"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg := NewFromCluster(cluster)
|
||||||
|
|
||||||
|
Expect(cfg.ReplicaSourceBarmanObjectName).To(BeEmpty())
|
||||||
|
Expect(cfg.Validate()).NotTo(Succeed())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user