-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
68 lines (56 loc) · 1.28 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
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"bytes"
"io/ioutil"
"os"
"strings"
"testing"
)
const (
inputFile = "./testdata/test1.md"
expFile = "./testdata/test1.md.html" //exp
)
func TestParseContent(t *testing.T) {
input, err := ioutil.ReadFile(inputFile)
if err != nil {
t.Fatal(err)
}
result, err := parseContent(input, "")
if err != nil {
t.Fatal(err)
}
expected, err := ioutil.ReadFile(expFile)
if err != nil {
t.Fatal(err)
}
if len(expected) != len(result) {
t.Logf("golden:\n%s\n", expected)
t.Logf("result:\n%s\n", result)
t.Error("Result content does not match golden file")
}
}
//update TestRun to take filename dynamically
func TestRun(t *testing.T) {
//mockStdout will hold the file name
//generated from calling the run()
var mockStdout bytes.Buffer
if err := run(inputFile, "", &mockStdout, true); err != nil {
t.Fatal(err)
}
//remove any space type character from the file name
resultFile := strings.TrimSpace(mockStdout.String())
got, err := ioutil.ReadFile(resultFile)
if err != nil {
t.Fatal(err)
}
expected, err := ioutil.ReadFile(expFile)
if err != nil {
t.Fatal(err)
}
if len(expected) != len(got) {
t.Logf("golden:\n%s\n", expected)
t.Logf("result:\n%s\n", got)
t.Error("Result content does not match golden file")
}
os.Remove(resultFile)
}