Skip to content

Commit 8b8fad1

Browse files
committed
Move requireStanzaExists to test suite helper
Multiple tests had similar implementations.
1 parent ac8d204 commit 8b8fad1

File tree

3 files changed

+19
-30
lines changed

3 files changed

+19
-30
lines changed

testing/pgo_cli/cluster_backup_test.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,6 @@ import (
3030
func TestClusterBackup(t *testing.T) {
3131
t.Parallel()
3232

33-
requireStanzaExists := func(t *testing.T, namespace, cluster string, timeout time.Duration) {
34-
t.Helper()
35-
36-
ready := func() bool {
37-
output, err := pgo("show", "backup", cluster, "-n", namespace).Exec(t)
38-
return err == nil && strings.Contains(output, "status: ok")
39-
}
40-
41-
if !ready() {
42-
requireWaitFor(t, ready, timeout, time.Second,
43-
"timeout waiting for stanza of %q in %q", cluster, namespace)
44-
}
45-
}
46-
4733
withNamespace(t, func(namespace func() string) {
4834
withCluster(t, namespace, func(cluster func() string) {
4935
t.Run("show backup", func(t *testing.T) {

testing/pgo_cli/cluster_clone_test.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package pgo_cli_test
1616
*/
1717

1818
import (
19-
"strings"
2019
"testing"
2120
"time"
2221

@@ -26,21 +25,6 @@ import (
2625
func TestClusterClone(t *testing.T) {
2726
t.Parallel()
2827

29-
requireStanzaExists := func(t *testing.T, namespace, cluster string, timeout time.Duration) {
30-
t.Helper()
31-
32-
ready := func() bool {
33-
output, err := pgo("show", "backup", cluster, "-n", namespace).Exec(t)
34-
require.NoError(t, err)
35-
return strings.Contains(output, "status: ok")
36-
}
37-
38-
if !ready() {
39-
requireWaitFor(t, ready, timeout, time.Second,
40-
"timeout waiting for stanza of %q in %q", cluster, namespace)
41-
}
42-
}
43-
4428
withNamespace(t, func(namespace func() string) {
4529
withCluster(t, namespace, func(cluster func() string) {
4630
t.Run("clone", func(t *testing.T) {

testing/pgo_cli/suite_helpers_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,25 @@ func requireReplicasReady(t testing.TB, namespace, cluster string, timeout time.
235235
}
236236
}
237237

238+
// requireStanzaExists waits until pgBackRest reports the stanza is ok. If
239+
// timeout elapses, t will FailNow.
240+
func requireStanzaExists(t testing.TB, namespace, cluster string, timeout time.Duration) {
241+
t.Helper()
242+
243+
var err error
244+
var output string
245+
246+
ready := func() bool {
247+
output, err = pgo("show", "backup", cluster, "-n", namespace).Exec(t)
248+
return err == nil && strings.Contains(output, "status: ok")
249+
}
250+
251+
if !ready() {
252+
requireWaitFor(t, ready, timeout, time.Second,
253+
"timeout waiting for stanza of %q in %q:\n%s", cluster, namespace, output)
254+
}
255+
}
256+
238257
// requireWaitFor calls condition every tick until it returns true. If timeout
239258
// elapses, t will Logf message and args then FailNow. Condition runs in the
240259
// current goroutine so that it may also call t.FailNow.

0 commit comments

Comments
 (0)