@cryptotaxi247 / kubo / commits / f4d361dd4

test: fix autoclient flakiness (#9769)

The test trims all whitespace bytes from the output of 'ipfs cat' but if the random bytes end in a whitespace char then it trims that too, resulting in random test failure. Instead this updates the test harness to only trim a single trailing newline char, so that it doesn't end up chomping legitimate output.

Gus Eggert committed Mar 29, 2023 at 11:56 UTC f4d361dd4e88fd799b83ecb2a8e0977f92f44524
2 files changed +11 -2
test/cli/dht_autoclient_test.go
+1
@@ -20,6 +20,7 @@ func TestDHTAutoclient(t *testing.T) {
20 t.Run("file added on node in client mode is retrievable from node in client mode", func(t *testing.T) {
21 t.Parallel()
22 randomBytes := testutils.RandomBytes(1000)
23 + randomBytes = append(randomBytes, '\r')
24 hash := nodes[8].IPFSAdd(bytes.NewReader(randomBytes))
25
26 res := nodes[9].IPFS("cat", hash)
test/cli/harness/buffer.go
+10 -2
@@ -25,11 +25,19 @@ func (b *Buffer) String() string {
25 return b.b.String()
26 }
27
28 -// Trimmed returns the bytes as a string, with leading and trailing whitespace removed.
28 +// Trimmed returns the bytes as a string, but with the trailing newline removed.
29 +// This only removes a single trailing newline, not all whitespace.
30 func (b *Buffer) Trimmed() string {
31 b.m.Lock()
32 defer b.m.Unlock()
32 - return strings.TrimSpace(b.b.String())
33 + s := b.b.String()
34 + if len(s) == 0 {
35 + return s
36 + }
37 + if s[len(s)-1] == '\n' {
38 + return s[:len(s)-1]
39 + }
40 + return s
41 }
42
43 func (b *Buffer) Bytes() []byte {