|
| 1 | +// Copyright 2026 Crunchy Data Solutions, Inc. |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +package bin_test |
| 6 | + |
| 7 | +import ( |
| 8 | + "os" |
| 9 | + "os/exec" |
| 10 | + "path/filepath" |
| 11 | + "testing" |
| 12 | + |
| 13 | + "gotest.tools/v3/assert" |
| 14 | +) |
| 15 | + |
| 16 | +func TestPgBackRestInfoScript(t *testing.T) { |
| 17 | + const script = "pgbackrest-info.sh" |
| 18 | + |
| 19 | + t.Run("Failure", func(t *testing.T) { |
| 20 | + dir := t.TempDir() |
| 21 | + pgbackrest := filepath.Join(dir, "pgbackrest") |
| 22 | + assert.NilError(t, os.WriteFile(pgbackrest, []byte("#!/bin/sh\nexit 42\n"), 0o700)) |
| 23 | + |
| 24 | + cmd := exec.CommandContext(t.Context(), "bash", script) |
| 25 | + cmd.Env = append(os.Environ(), "PATH="+dir) |
| 26 | + |
| 27 | + output, err := cmd.CombinedOutput() |
| 28 | + assert.ErrorContains(t, err, "exit status 42") |
| 29 | + assert.Equal(t, string(output), "|") |
| 30 | + }) |
| 31 | + |
| 32 | + t.Run("Success", func(t *testing.T) { |
| 33 | + dir := t.TempDir() |
| 34 | + pgbackrest := filepath.Join(dir, "pgbackrest") |
| 35 | + assert.NilError(t, os.WriteFile(pgbackrest, []byte("#!/bin/sh\nprintf '[{}]'\n"), 0o700)) |
| 36 | + |
| 37 | + cmd := exec.CommandContext(t.Context(), "bash", script) |
| 38 | + cmd.Env = append(os.Environ(), "PATH="+dir) |
| 39 | + |
| 40 | + output, err := cmd.CombinedOutput() |
| 41 | + assert.NilError(t, err) |
| 42 | + assert.Equal(t, string(output), "|[{}]\n") |
| 43 | + }) |
| 44 | +} |
0 commit comments