From adcb2198e58c111d309b6eac8c448a12577f51f9 Mon Sep 17 00:00:00 2001 From: immanuwell Date: Wed, 13 May 2026 21:21:16 +0400 Subject: [PATCH] fix: propagate pgbackrest info failures --- .../image-postgres/bin/pgbackrest-info.sh | 2 + .../bin/pgbackrest-info_test.go | 44 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 components/image-postgres/bin/pgbackrest-info_test.go diff --git a/components/image-postgres/bin/pgbackrest-info.sh b/components/image-postgres/bin/pgbackrest-info.sh index e36232c8a..bbc2e377d 100755 --- a/components/image-postgres/bin/pgbackrest-info.sh +++ b/components/image-postgres/bin/pgbackrest-info.sh @@ -4,6 +4,8 @@ # # SPDX-License-Identifier: Apache-2.0 +set -e + printf '|' pgbackrest info --output=json --log-level-console=info --log-level-stderr=warn echo diff --git a/components/image-postgres/bin/pgbackrest-info_test.go b/components/image-postgres/bin/pgbackrest-info_test.go new file mode 100644 index 000000000..57e0d8418 --- /dev/null +++ b/components/image-postgres/bin/pgbackrest-info_test.go @@ -0,0 +1,44 @@ +// Copyright 2026 Crunchy Data Solutions, Inc. +// +// SPDX-License-Identifier: Apache-2.0 + +package bin_test + +import ( + "os" + "os/exec" + "path/filepath" + "testing" + + "gotest.tools/v3/assert" +) + +func TestPgBackRestInfoScript(t *testing.T) { + const script = "pgbackrest-info.sh" + + t.Run("Failure", func(t *testing.T) { + dir := t.TempDir() + pgbackrest := filepath.Join(dir, "pgbackrest") + assert.NilError(t, os.WriteFile(pgbackrest, []byte("#!/bin/sh\nexit 42\n"), 0o700)) + + cmd := exec.CommandContext(t.Context(), "bash", script) + cmd.Env = append(os.Environ(), "PATH="+dir) + + output, err := cmd.CombinedOutput() + assert.ErrorContains(t, err, "exit status 42") + assert.Equal(t, string(output), "|") + }) + + t.Run("Success", func(t *testing.T) { + dir := t.TempDir() + pgbackrest := filepath.Join(dir, "pgbackrest") + assert.NilError(t, os.WriteFile(pgbackrest, []byte("#!/bin/sh\nprintf '[{}]'\n"), 0o700)) + + cmd := exec.CommandContext(t.Context(), "bash", script) + cmd.Env = append(os.Environ(), "PATH="+dir) + + output, err := cmd.CombinedOutput() + assert.NilError(t, err) + assert.Equal(t, string(output), "|[{}]\n") + }) +}