-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathexec_test.go
More file actions
171 lines (139 loc) · 5.03 KB
/
Copy pathexec_test.go
File metadata and controls
171 lines (139 loc) · 5.03 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Copyright 2021 - 2025 Crunchy Data Solutions, Inc.
//
// SPDX-License-Identifier: Apache-2.0
package cmd
import (
"errors"
"io"
"testing"
"gotest.tools/v3/assert"
)
func TestPGBackRestInfo(t *testing.T) {
t.Run("default", func(t *testing.T) {
expected := errors.New("pass-through")
exec := func(
stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
assert.DeepEqual(t, command, []string{"bash", "-ceu", "--", "pgbackrest info --output=text"})
assert.Assert(t, stdout != nil, "should capture stdout")
assert.Assert(t, stderr != nil, "should capture stderr")
return expected
}
_, _, err := Executor(exec).pgBackRestInfo("text", "")
assert.ErrorContains(t, err, "pass-through")
})
t.Run("text, repo 1", func(t *testing.T) {
expected := errors.New("pass-through")
exec := func(
stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
assert.DeepEqual(t, command, []string{"bash", "-ceu", "--", "pgbackrest info --output=text --repo=1"})
assert.Assert(t, stdout != nil, "should capture stdout")
assert.Assert(t, stderr != nil, "should capture stderr")
return expected
}
_, _, err := Executor(exec).pgBackRestInfo("text", "1")
assert.ErrorContains(t, err, "pass-through")
})
t.Run("json, repo 2", func(t *testing.T) {
expected := errors.New("pass-through")
exec := func(
stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
assert.DeepEqual(t, command, []string{"bash", "-ceu", "--", "pgbackrest info --output=json --repo=2"})
assert.Assert(t, stdout != nil, "should capture stdout")
assert.Assert(t, stderr != nil, "should capture stderr")
return expected
}
_, _, err := Executor(exec).pgBackRestInfo("json", "2")
assert.ErrorContains(t, err, "pass-through")
})
}
func TestListPGLogFiles(t *testing.T) {
t.Run("default", func(t *testing.T) {
expected := errors.New("pass-through")
exec := func(
stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
assert.DeepEqual(t, command, []string{"bash", "-ceu", "--", "ls -1dt pgdata/pg[0-9][0-9]/log/* | head -1"})
assert.Assert(t, stdout != nil, "should capture stdout")
assert.Assert(t, stderr != nil, "should capture stderr")
return expected
}
_, _, err := Executor(exec).listPGLogFiles(1, false)
assert.ErrorContains(t, err, "pass-through")
})
t.Run("has instrumentation", func(t *testing.T) {
expected := errors.New("pass-through")
exec := func(
stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
assert.DeepEqual(t, command, []string{"bash", "-ceu", "--", "ls -1dt pgdata/logs/postgres/*.* | head -1"})
assert.Assert(t, stdout != nil, "should capture stdout")
assert.Assert(t, stderr != nil, "should capture stderr")
return expected
}
_, _, err := Executor(exec).listPGLogFiles(1, true)
assert.ErrorContains(t, err, "pass-through")
})
}
func TestListPatroniLogFiles(t *testing.T) {
t.Run("default", func(t *testing.T) {
expected := errors.New("pass-through")
exec := func(
stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
assert.DeepEqual(t, command, []string{"bash", "-ceu", "--", "ls -1dt pgdata/patroni/log/*.*"})
assert.Assert(t, stdout != nil, "should capture stdout")
assert.Assert(t, stderr != nil, "should capture stderr")
return expected
}
_, _, err := Executor(exec).listPatroniLogFiles()
assert.ErrorContains(t, err, "pass-through")
})
}
func TestCatFile(t *testing.T) {
t.Run("default", func(t *testing.T) {
expected := errors.New("pass-through")
exec := func(
stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
assert.DeepEqual(t, command, []string{"bash", "-ceu", "--", "cat /path/to/file"})
assert.Assert(t, stdout != nil, "should capture stdout")
assert.Assert(t, stderr != nil, "should capture stderr")
return expected
}
_, _, err := Executor(exec).catFile("/path/to/file")
assert.ErrorContains(t, err, "pass-through")
})
}
func TestPatronictl(t *testing.T) {
t.Run("default", func(t *testing.T) {
expected := errors.New("pass-through")
exec := func(
stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
assert.DeepEqual(t, command, []string{"bash", "-ceu", "--", "patronictl sub-command"})
assert.Assert(t, stdout != nil, "should capture stdout")
assert.Assert(t, stderr != nil, "should capture stderr")
return expected
}
_, _, err := Executor(exec).patronictl("sub-command", "")
assert.ErrorContains(t, err, "pass-through")
})
}
func TestProcesses(t *testing.T) {
t.Run("default", func(t *testing.T) {
expected := errors.New("pass-through")
exec := func(
stdin io.Reader, stdout, stderr io.Writer, command ...string,
) error {
assert.DeepEqual(t, command, []string{"bash", "-ceu", "--", "ps aux --width 500"})
assert.Assert(t, stdout != nil, "should capture stdout")
assert.Assert(t, stderr != nil, "should capture stderr")
return expected
}
_, _, err := Executor(exec).processes()
assert.ErrorContains(t, err, "pass-through")
})
}