Skip to content

Commit

Permalink
Fix test that asserts on full log line
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskorn committed Jul 29, 2024
1 parent e75df2b commit 5b78a5b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/storage/ingest/pusher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package ingest
import (
"context"
"fmt"
"regexp"
"strings"
"testing"

Expand Down Expand Up @@ -211,12 +212,25 @@ func TestPusherConsumer(t *testing.T) {
var logLines []string
if logsStr := logs.String(); logsStr != "" {
logLines = strings.Split(strings.TrimSpace(logsStr), "\n")
logLines = removeUnimportantLogFields(logLines)
}
assert.Equal(t, tc.expectedLogLines, logLines)
})
}
}

var unimportantLogFieldsPattern = regexp.MustCompile(`\scaller=\S+\.go:\d+\s`)

func removeUnimportantLogFields(lines []string) []string {
// The 'caller' field is not important to these tests (we just care about the message and other information),
// and can change as we refactor code, making these tests brittle. So we remove it before making assertions about the log lines.
for i, line := range lines {
lines[i] = unimportantLogFieldsPattern.ReplaceAllString(line, " ")
}

return lines
}

func TestPusherConsumer_clientErrorSampling(t *testing.T) {
type testCase struct {
sampler *util_log.Sampler
Expand Down

0 comments on commit 5b78a5b

Please sign in to comment.