MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / TestSecret

Function TestSecret

internal/pgbouncer/reconcile_test.go:53–92  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

51}
52
53func TestSecret(t *testing.T) {
54 t.Parallel()
55
56 ctx := context.Background()
57 cluster := new(v1beta1.PostgresCluster)
58 service := new(corev1.Service)
59 existing := new(corev1.Secret)
60 intent := new(corev1.Secret)
61
62 root, err := pki.NewRootCertificateAuthority()
63 assert.NilError(t, err)
64
65 t.Run("Disabled", func(t *testing.T) {
66 // Nothing happens when PgBouncer is disabled.
67 constant := intent.DeepCopy()
68 assert.NilError(t, Secret(ctx, cluster, root, existing, service, intent))
69 assert.DeepEqual(t, constant, intent)
70 })
71
72 cluster.Spec.Proxy = new(v1beta1.PostgresProxySpec)
73 cluster.Spec.Proxy.PGBouncer = new(v1beta1.PGBouncerPodSpec)
74 cluster.Default()
75
76 constant := existing.DeepCopy()
77 assert.NilError(t, Secret(ctx, cluster, root, existing, service, intent))
78 assert.DeepEqual(t, constant, existing)
79
80 // A password should be generated.
81 assert.Assert(t, len(intent.Data["pgbouncer-password"]) != 0)
82 assert.Assert(t, len(intent.Data["pgbouncer-verifier"]) != 0)
83
84 // The output of authFileContents should go into intent.
85 assert.Assert(t, len(intent.Data["pgbouncer-users.txt"]) != 0)
86
87 // Assuming the intent is written, no change when called again.
88 existing.Data = intent.Data
89 before := intent.DeepCopy()
90 assert.NilError(t, Secret(ctx, cluster, root, existing, service, intent))
91 assert.DeepEqual(t, before, intent)
92}
93
94func TestSCRAMVerifier(t *testing.T) {
95 t.Parallel()

Callers

nothing calls this directly

Calls 4

SecretFunction · 0.70
DeepCopyMethod · 0.45
DefaultMethod · 0.45

Tested by

no test coverage detected