-
Notifications
You must be signed in to change notification settings - Fork 10
/
main_test.go
55 lines (48 loc) · 1.16 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"bufio"
"bytes"
"io/ioutil"
"os"
"regexp"
"strings"
"testing"
)
var (
inDir = "testdata/input/"
outDir = "testdata/output/"
timestampRegexp = regexp.MustCompile(`timestamp='.*?'`)
timestampReplacement = `timestamp='2017-01-02T04:05:06.789'`
)
func TestProcessReader(t *testing.T) {
files, err := ioutil.ReadDir(inDir)
if err != nil {
t.Error(err)
}
for _, file := range files {
t.Run(file.Name(), func(t *testing.T) {
inpath := inDir + file.Name()
f, err := os.Open(inpath)
if err != nil {
t.Error(err)
}
in := bufio.NewReader(f)
out := &bytes.Buffer{}
processReader(in, out)
actual := out.String()
actual = timestampRegexp.ReplaceAllString(actual, timestampReplacement)
outpath := outDir + file.Name()
t.Logf("input: %s", inpath)
t.Logf("output: %s", outpath)
expectedBytes, err := ioutil.ReadFile(outpath)
if err != nil {
t.Error(err)
}
expected := string(expectedBytes)
expected = timestampRegexp.ReplaceAllString(expected, timestampReplacement)
if strings.Compare(expected, actual) != 0 {
t.Errorf("expected:\n\n%s\nbut got:\n\n%s\n", expected, actual)
}
})
}
}