Skip to content

Commit 17f437c

Browse files
committed
trim
1 parent 318856d commit 17f437c

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

tests/systemtests/export_test.go

+21-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"os"
88
"path/filepath"
9+
"regexp"
910
"strings"
1011
"testing"
1112

@@ -17,6 +18,25 @@ import (
1718
systest "cosmossdk.io/systemtests"
1819
)
1920

21+
// PebbleDB logs are printed directly to stderr.
22+
// Cosmos-DB and Store/v2 do not provide a way to override the logger.
23+
// This isn't problematic in a real-world scenario, but it makes it hard to test the output.
24+
// https://github.com/cockroachdb/pebble/blob/v1.1.2/internal/base/logger.go#L26-L40
25+
func trimPebbleDBStdErr(input string) string {
26+
re := regexp.MustCompile(`^\[JOB \d+\] WAL .+ stopped reading at offset: .+; replayed \d+ keys in \d+ batches$`)
27+
28+
lines := strings.Split(input, "\n")
29+
// filter out lines that match the regex
30+
var filtered []string
31+
for _, line := range lines {
32+
if !re.MatchString(line) {
33+
filtered = append(filtered, line)
34+
}
35+
}
36+
37+
return strings.Join(filtered, "\n")
38+
}
39+
2040
func TestChainExportImport(t *testing.T) {
2141
// Scenario:
2242
// given: a state dump from a running chain
@@ -69,12 +89,7 @@ func TestExportCmd_WithHeight(t *testing.T) {
6989

7090
for _, tc := range testCases {
7191
res := cli.RunCommandWithArgs(tc.args...)
72-
// sometimes the output contains some logs, so we need to extract the json part
73-
if i := strings.Index(res, "{"); i > 0 {
74-
res = res[i:]
75-
}
76-
77-
height := gjson.Get(res, "initial_height").Int()
92+
height := gjson.Get(trimPebbleDBStdErr(res), "initial_height").Int()
7893
if tc.expZeroHeight {
7994
require.Equal(t, height, int64(0))
8095
} else {

tests/systemtests/snapshots_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestSnapshots(t *testing.T) {
4242

4343
// Check snapshots list
4444
res = cli.RunCommandWithArgs(command, "list", fmt.Sprintf("--home=%s", node0Dir))
45-
require.Contains(t, res, "height: 5")
45+
require.Contains(t, trimPebbleDBStdErr(res), "height: 5")
4646

4747
// Dump snapshot
4848
res = cli.RunCommandWithArgs(command, "dump", "5", "3", fmt.Sprintf("--home=%s", node0Dir), fmt.Sprintf("--output=%s/5-3.tar.gz", node0Dir))

0 commit comments

Comments
 (0)