extending unit tests

This commit is contained in:
Felix Kunde 2022-03-30 16:21:40 +02:00
parent d78ccea3a8
commit a1908d4c59
4 changed files with 43 additions and 10 deletions

View File

@ -1087,9 +1087,9 @@ data:
### Standby clusters ### Standby clusters
The setup for [standby clusters](user.md#setting-up-a-standby-cluster) is very The setup for [standby clusters](user.md#setting-up-a-standby-cluster) is
similar to cloning. They can stream from a WAL archive (S3, GCS). Like with similar to cloning when they stream changes from a WAL archive (S3 or GCS).
cloning, if you are using [additional environment variables](#custom-pod-environment-variables) If you are using [additional environment variables](#custom-pod-environment-variables)
to access your backup location you have to copy those variables and prepend to access your backup location you have to copy those variables and prepend
the `STANDBY_` prefix for Spilo to find the backups and WAL files to stream. the `STANDBY_` prefix for Spilo to find the backups and WAL files to stream.

View File

@ -170,7 +170,7 @@ type Patroni struct {
SynchronousNodeCount uint32 `json:"synchronous_node_count,omitempty" defaults:"1"` SynchronousNodeCount uint32 `json:"synchronous_node_count,omitempty" defaults:"1"`
} }
// StandbyDescription contains remote primary config or s3 wal path // StandbyDescription contains remote primary config or s3/gs wal path
type StandbyDescription struct { type StandbyDescription struct {
S3WalPath string `json:"s3_wal_path,omitempty"` S3WalPath string `json:"s3_wal_path,omitempty"`
GSWalPath string `json:"gs_wal_path,omitempty"` GSWalPath string `json:"gs_wal_path,omitempty"`

View File

@ -1963,7 +1963,6 @@ func (c *Cluster) generateStandbyEnvironment(description *acidv1.StandbyDescript
result = append(result, v1.EnvVar{Name: "STANDBY_METHOD", Value: "STANDBY_WITH_WALE"}) result = append(result, v1.EnvVar{Name: "STANDBY_METHOD", Value: "STANDBY_WITH_WALE"})
result = append(result, v1.EnvVar{Name: "STANDBY_WAL_BUCKET_SCOPE_PREFIX", Value: ""}) result = append(result, v1.EnvVar{Name: "STANDBY_WAL_BUCKET_SCOPE_PREFIX", Value: ""})
} }
return result return result

View File

@ -538,6 +538,7 @@ func TestStandbyEnv(t *testing.T) {
standbyOpts *acidv1.StandbyDescription standbyOpts *acidv1.StandbyDescription
env v1.EnvVar env v1.EnvVar
envPos int envPos int
envLen int
}{ }{
{ {
subTest: "from custom s3 path", subTest: "from custom s3 path",
@ -549,6 +550,7 @@ func TestStandbyEnv(t *testing.T) {
Value: "s3://some/path/", Value: "s3://some/path/",
}, },
envPos: 0, envPos: 0,
envLen: 3,
}, },
{ {
subTest: "from custom gs path", subTest: "from custom gs path",
@ -556,15 +558,28 @@ func TestStandbyEnv(t *testing.T) {
GSWalPath: "gs://some/path/", GSWalPath: "gs://some/path/",
}, },
env: v1.EnvVar{ env: v1.EnvVar{
Name: "STANDBY_WALE_GS_PREFIX", Name: "STANDBY_GOOGLE_APPLICATION_CREDENTIALS",
Value: "gs://some/path/", Value: "",
}, },
envPos: 0, envPos: 1,
envLen: 4,
},
{
subTest: "ignore gs path if s3 is set",
standbyOpts: &acidv1.StandbyDescription{
S3WalPath: "s3://some/path/",
GSWalPath: "gs://some/path/",
},
env: v1.EnvVar{
Name: "STANDBY_METHOD",
Value: "STANDBY_WITH_WALE",
},
envPos: 1,
envLen: 3,
}, },
{ {
subTest: "from remote primary", subTest: "from remote primary",
standbyOpts: &acidv1.StandbyDescription{ standbyOpts: &acidv1.StandbyDescription{
S3WalPath: "s3://some/path/",
StandbyHost: "remote-primary", StandbyHost: "remote-primary",
}, },
env: v1.EnvVar{ env: v1.EnvVar{
@ -572,11 +587,11 @@ func TestStandbyEnv(t *testing.T) {
Value: "remote-primary", Value: "remote-primary",
}, },
envPos: 0, envPos: 0,
envLen: 1,
}, },
{ {
subTest: "from remote primary with port", subTest: "from remote primary with port",
standbyOpts: &acidv1.StandbyDescription{ standbyOpts: &acidv1.StandbyDescription{
S3WalPath: "s3://some/path/",
StandbyHost: "remote-primary", StandbyHost: "remote-primary",
StandbyPort: "9876", StandbyPort: "9876",
}, },
@ -585,6 +600,20 @@ func TestStandbyEnv(t *testing.T) {
Value: "9876", Value: "9876",
}, },
envPos: 1, envPos: 1,
envLen: 2,
},
{
subTest: "from remote primary - ignore WAL path",
standbyOpts: &acidv1.StandbyDescription{
GSWalPath: "gs://some/path/",
StandbyHost: "remote-primary",
},
env: v1.EnvVar{
Name: "STANDBY_HOST",
Value: "remote-primary",
},
envPos: 0,
envLen: 1,
}, },
} }
@ -605,6 +634,11 @@ func TestStandbyEnv(t *testing.T) {
t.Errorf("%s %s: Expected env value %s, have %s instead", t.Errorf("%s %s: Expected env value %s, have %s instead",
testName, tt.subTest, tt.env.Value, env.Value) testName, tt.subTest, tt.env.Value, env.Value)
} }
if len(envs) != tt.envLen {
t.Errorf("%s %s: Expected number of env variables %d, have %d instead",
testName, tt.subTest, tt.envLen, len(envs))
}
} }
} }