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

Function TestReloadCommand

internal/postgres/config_test.go:617–656  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

615}
616
617func TestReloadCommand(t *testing.T) {
618 shellcheck := require.ShellCheck(t)
619
620 pgdataSize := resource.MustParse("1Gi")
621 pgwalSize := resource.MustParse("2Gi")
622
623 command := reloadCommand(
624 "some-name",
625 &v1beta1.VolumeClaimSpecWithAutoGrow{
626 AutoGrow: &v1beta1.AutoGrowSpec{
627 Trigger: initialize.Int32(10),
628 MaxGrow: &pgdataSize,
629 },
630 },
631 &v1beta1.VolumeClaimSpecWithAutoGrow{
632 AutoGrow: &v1beta1.AutoGrowSpec{
633 Trigger: initialize.Int32(20),
634 MaxGrow: &pgwalSize,
635 },
636 },
637 )
638
639 // Expect a bash command with an inline script.
640 assert.DeepEqual(t, command[:3], []string{"bash", "-ceu", "--"})
641 assert.Assert(t, len(command) > 3)
642
643 // Write out that inline script.
644 dir := t.TempDir()
645 file := filepath.Join(dir, "script.bash")
646 assert.NilError(t, os.WriteFile(file, []byte(command[3]), 0o600))
647
648 // Expect shellcheck to be happy.
649 cmd := exec.CommandContext(t.Context(), shellcheck, "--enable=all", file)
650 output, err := cmd.CombinedOutput()
651 assert.NilError(t, err, "%q\n%s", cmd.Args, output)
652
653 assert.Assert(t, cmp.Contains(command[3], "manageAutogrowAnnotation \"pgdata\" \"10\" \"1024\""))
654 assert.Assert(t, cmp.Contains(command[3], "manageAutogrowAnnotation \"pgwal\" \"20\" \"2048\""))
655
656}

Callers

nothing calls this directly

Calls 4

ShellCheckFunction · 0.92
Int32Function · 0.92
ContainsFunction · 0.92
reloadCommandFunction · 0.70

Tested by

no test coverage detected