(t *testing.T)
| 548 | } |
| 549 | |
| 550 | func TestShellPath(t *testing.T) { |
| 551 | t.Parallel() |
| 552 | |
| 553 | script := ShellPath(11) |
| 554 | |
| 555 | assert.Assert(t, cmp.Contains(script, `/usr/lib/postgresql/11/bin`)) |
| 556 | assert.Assert(t, cmp.Contains(script, `/usr/libexec/postgresql11`)) |
| 557 | assert.Assert(t, cmp.Contains(script, `/usr/pgsql-11/bin`)) |
| 558 | |
| 559 | t.Run("ShellCheckPOSIX", func(t *testing.T) { |
| 560 | shellcheck := require.ShellCheck(t) |
| 561 | |
| 562 | dir := t.TempDir() |
| 563 | file := filepath.Join(dir, "script.sh") |
| 564 | assert.NilError(t, os.WriteFile(file, []byte(script), 0o600)) |
| 565 | |
| 566 | // Expect ShellCheck for "sh" to be happy. |
| 567 | // - https://www.shellcheck.net/wiki/SC2148 |
| 568 | cmd := exec.CommandContext(t.Context(), shellcheck, "--enable=all", "--shell=sh", file) |
| 569 | output, err := cmd.CombinedOutput() |
| 570 | assert.NilError(t, err, "%q\n%s", cmd.Args, output) |
| 571 | }) |
| 572 | |
| 573 | t.Run("PrettyYAML", func(t *testing.T) { |
| 574 | b, err := yaml.Marshal(script) |
| 575 | assert.NilError(t, err) |
| 576 | assert.Assert(t, !strings.Contains(string(b), `\n`), "expected literal flow scalar, got:\n%s", b) |
| 577 | assert.Equal(t, 1, strings.Count(string(b), "\n"), "expected one trailing newline, got:\n%s", b) |
| 578 | }) |
| 579 | } |
| 580 | |
| 581 | func TestStartupCommand(t *testing.T) { |
| 582 | shellcheck := require.ShellCheck(t) |
nothing calls this directly
no test coverage detected