From c197bec7e7a5b55f5be6096b1f283a2439190386 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 | 46 +++++++++++++++++++ 2 files changed, 48 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 e36232c8a0..bbc2e377d1 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 0000000000..c4b7996987 --- /dev/null +++ b/components/image-postgres/bin/pgbackrest-info_test.go @@ -0,0 +1,46 @@ +// 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"), 0o600)) + assert.NilError(t, os.Chmod(pgbackrest, 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"), 0o600)) + assert.NilError(t, os.Chmod(pgbackrest, 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") + }) +}