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

Function TestStartupCommand

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

Source from the content-addressed store, hash-verified

579}
580
581func TestStartupCommand(t *testing.T) {
582 shellcheck := require.ShellCheck(t)
583 t.Parallel()
584
585 cluster := new(v1beta1.PostgresCluster)
586 cluster.Spec.PostgresVersion = 13
587 instance := new(v1beta1.PostgresInstanceSetSpec)
588
589 parameters := NewParameters().Default
590
591 ctx := context.Background()
592 command := startupCommand(ctx, cluster, instance, parameters)
593
594 // Expect a bash command with an inline script.
595 assert.DeepEqual(t, command[:3], []string{"bash", "-ceu", "--"})
596 assert.Assert(t, len(command) > 3)
597 script := command[3]
598
599 // Write out that inline script.
600 dir := t.TempDir()
601 file := filepath.Join(dir, "script.bash")
602 assert.NilError(t, os.WriteFile(file, []byte(script), 0o600))
603
604 // Expect shellcheck to be happy.
605 cmd := exec.CommandContext(t.Context(), shellcheck, "--enable=all", file)
606 output, err := cmd.CombinedOutput()
607 assert.NilError(t, err, "%q\n%s", cmd.Args, output)
608
609 t.Run("PrettyYAML", func(t *testing.T) {
610 b, err := yaml.Marshal(script)
611 assert.NilError(t, err)
612 assert.Assert(t, strings.HasPrefix(string(b), `|`),
613 "expected literal block scalar, got:\n%s", b)
614 })
615}
616
617func TestReloadCommand(t *testing.T) {
618 shellcheck := require.ShellCheck(t)

Callers

nothing calls this directly

Calls 3

ShellCheckFunction · 0.92
NewParametersFunction · 0.85
startupCommandFunction · 0.70

Tested by

no test coverage detected