(t *testing.T)
| 51 | } |
| 52 | |
| 53 | func 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 | |
| 94 | func TestSCRAMVerifier(t *testing.T) { |
| 95 | t.Parallel() |
nothing calls this directly
no test coverage detected