-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
50 lines (40 loc) · 938 Bytes
/
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
package main
import (
"bytes"
"io/ioutil"
"os"
"testing"
)
const dstFilepath = "_testdata/dst.jpg"
func TestRun(t *testing.T) {
var buf bytes.Buffer
if err := run("test", &buf); err != nil {
t.Fatalf("Should not be fail: %v.", err)
}
if os.Getenv("IS_CREATE_DST_FILE") == "true" {
createDstFile(t, buf.Bytes())
}
dstFile, err := os.Open(dstFilepath)
if err != nil {
t.Fatalf("Should not be fail: %v.", err)
}
want, err := ioutil.ReadAll(dstFile)
if err != nil {
t.Fatalf("Should not be fail: %v.", err)
}
if got := buf.Bytes(); !bytes.Equal(got, want) {
t.Fatalf("Should be same as %s.", dstFilepath)
}
}
func createDstFile(t *testing.T, bs []byte) {
t.Helper()
f, err := os.Create(dstFilepath)
if err != nil {
t.Fatalf("Should not be fail: %v.", err)
}
defer f.Close()
if _, err := f.Write(bs); err != nil {
t.Fatalf("Should not be fail: %v.", err)
}
t.Skip("Create destination file.")
}