Skip to content

Commit 6da49fc

Browse files
committed
update tests
1 parent 4955e4c commit 6da49fc

File tree

6 files changed

+43
-5
lines changed

6 files changed

+43
-5
lines changed

internal/collector/patroni_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"gotest.tools/v3/assert"
1212

1313
"github.com/crunchydata/postgres-operator/internal/feature"
14+
"github.com/crunchydata/postgres-operator/internal/testing/require"
1415
"github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
1516
)
1617

@@ -23,8 +24,14 @@ func TestEnablePatroniLogging(t *testing.T) {
2324
ctx := feature.NewContext(context.Background(), gate)
2425

2526
config := NewConfig(nil)
27+
cluster := new(v1beta1.PostgresCluster)
28+
require.UnmarshalInto(t, &cluster.Spec, `{
29+
instrumentation: {
30+
logs: { retentionPeriod: 5h },
31+
},
32+
}`)
2633

27-
EnablePatroniLogging(ctx, new(v1beta1.PostgresCluster), config)
34+
EnablePatroniLogging(ctx, cluster, config)
2835

2936
result, err := config.ToYAML()
3037
assert.NilError(t, err)

internal/collector/pgadmin_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ func TestEnablePgAdminLogging(t *testing.T) {
3030

3131
configmap := new(corev1.ConfigMap)
3232
initialize.Map(&configmap.Data)
33-
err := collector.EnablePgAdminLogging(ctx, nil, configmap)
33+
retentionPeriod, err := v1beta1.NewDuration("12 hours")
34+
assert.NilError(t, err)
35+
instrumentation := v1beta1.InstrumentationSpec{
36+
Logs: &v1beta1.InstrumentationLogsSpec{
37+
RetentionPeriod: retentionPeriod,
38+
},
39+
}
40+
err = collector.EnablePgAdminLogging(ctx, &instrumentation, configmap)
3441
assert.NilError(t, err)
3542

3643
assert.Assert(t, cmp.MarshalMatches(configmap.Data, `

internal/collector/pgbackrest_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ func TestNewConfigForPgBackrestRepoHostPod(t *testing.T) {
2727
Volume: new(v1beta1.RepoPVC),
2828
},
2929
}
30+
retentionPeriod, err := v1beta1.NewDuration("12 hours")
31+
assert.NilError(t, err)
32+
instrumentation := v1beta1.InstrumentationSpec{
33+
Logs: &v1beta1.InstrumentationLogsSpec{
34+
RetentionPeriod: retentionPeriod,
35+
},
36+
}
3037

31-
config := NewConfigForPgBackrestRepoHostPod(ctx, nil, repos)
38+
config := NewConfigForPgBackrestRepoHostPod(ctx, &instrumentation, repos)
3239

3340
result, err := config.ToYAML()
3441
assert.NilError(t, err)

internal/collector/pgbouncer_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"gotest.tools/v3/assert"
1212

1313
"github.com/crunchydata/postgres-operator/internal/feature"
14+
"github.com/crunchydata/postgres-operator/internal/testing/require"
1415
"github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
1516
)
1617

@@ -23,8 +24,13 @@ func TestEnablePgBouncerLogging(t *testing.T) {
2324
ctx := feature.NewContext(context.Background(), gate)
2425

2526
config := NewConfig(nil)
26-
27-
EnablePgBouncerLogging(ctx, new(v1beta1.PostgresCluster), config)
27+
cluster := new(v1beta1.PostgresCluster)
28+
require.UnmarshalInto(t, &cluster.Spec, `{
29+
instrumentation: {
30+
logs: { retentionPeriod: 5h },
31+
},
32+
}`)
33+
EnablePgBouncerLogging(ctx, cluster, config)
2834

2935
result, err := config.ToYAML()
3036
assert.NilError(t, err)

internal/collector/postgres_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/crunchydata/postgres-operator/internal/feature"
1414
"github.com/crunchydata/postgres-operator/internal/postgres"
15+
"github.com/crunchydata/postgres-operator/internal/testing/require"
1516
"github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
1617
)
1718

@@ -25,6 +26,11 @@ func TestEnablePostgresLogging(t *testing.T) {
2526

2627
cluster := new(v1beta1.PostgresCluster)
2728
cluster.Spec.PostgresVersion = 99
29+
require.UnmarshalInto(t, &cluster.Spec, `{
30+
instrumentation: {
31+
logs: { retentionPeriod: 5h },
32+
},
33+
}`)
2834

2935
config := NewConfig(nil)
3036
params := postgres.NewParameterSet()

internal/controller/postgrescluster/cluster_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,11 @@ func TestPatroniLogSize(t *testing.T) {
870870
reconciler := &Reconciler{Recorder: recorder}
871871

872872
cluster.Spec.Patroni = nil
873+
require.UnmarshalInto(t, &cluster.Spec, `{
874+
instrumentation: {
875+
logs: { retentionPeriod: 5h },
876+
},
877+
}`)
873878

874879
size := reconciler.patroniLogSize(ctx, &cluster)
875880

0 commit comments

Comments
 (0)