Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions components/image-postgres/bin/pgbackrest-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
44 changes: 44 additions & 0 deletions components/image-postgres/bin/pgbackrest-info_test.go
Original file line number Diff line number Diff line change
@@ -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))

Check failure on line 22 in components/image-postgres/bin/pgbackrest-info_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

G306: Expect WriteFile permissions to be 0600 or less (gosec)

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))

Check failure on line 35 in components/image-postgres/bin/pgbackrest-info_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

G306: Expect WriteFile permissions to be 0600 or less (gosec)

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")
})
}
Loading