Skip to content

Commit

Permalink
fix: normalize "N months ago" in test expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
sqs committed Aug 28, 2018
1 parent a184d40 commit 190e550
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/src/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"testing"
)
Expand Down Expand Up @@ -92,6 +93,8 @@ func TestSearchOutput(t *testing.T) {
t.Fatal(err)
}
got := buf.String()
normalizeTimeAgo(&got)
normalizeTimeAgo(tst.want)
if got != *tst.want {
t.Logf("'%s.want.txt' does not match '%s.got.txt'", testName, testName)
gotFile := filepath.Join(dataDir, testName+".got.txt")
Expand All @@ -109,3 +112,10 @@ func TestSearchOutput(t *testing.T) {
})
}
}

var nMonthsAgoPattern = regexp.MustCompile(`\d+ months? ago`)

// normalizeTimeAgo makes tests not depend on the current time.
func normalizeTimeAgo(s *string) {
*s = nMonthsAgoPattern.ReplaceAllString(*s, "N months ago")
}

0 comments on commit 190e550

Please sign in to comment.