6
6
"fmt"
7
7
"os"
8
8
"path/filepath"
9
+ "regexp"
9
10
"strings"
10
11
"testing"
11
12
@@ -17,6 +18,25 @@ import (
17
18
systest "cosmossdk.io/systemtests"
18
19
)
19
20
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
+
20
40
func TestChainExportImport (t * testing.T ) {
21
41
// Scenario:
22
42
// given: a state dump from a running chain
@@ -69,12 +89,7 @@ func TestExportCmd_WithHeight(t *testing.T) {
69
89
70
90
for _ , tc := range testCases {
71
91
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 ()
78
93
if tc .expZeroHeight {
79
94
require .Equal (t , height , int64 (0 ))
80
95
} else {
0 commit comments