Skip to content

Commit adcb219

Browse files
committed
fix: propagate pgbackrest info failures
1 parent 68542c6 commit adcb219

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

components/image-postgres/bin/pgbackrest-info.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

7+
set -e
8+
79
printf '|'
810
pgbackrest info --output=json --log-level-console=info --log-level-stderr=warn
911
echo
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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

Comments
 (0)