-
Notifications
You must be signed in to change notification settings - Fork 669
Expand file tree
/
Copy pathpgbackrest-info_test.go
More file actions
44 lines (34 loc) · 1.1 KB
/
pgbackrest-info_test.go
File metadata and controls
44 lines (34 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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")
})
}