-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_test.go
46 lines (35 loc) · 875 Bytes
/
file_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
package main
import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
func TestPatchFileParsing(t *testing.T) {
fileList := getDirectoryContents(filepath.Join("testdata", "Patch"))
if len(fileList) < 1 {
t.Error("Couldn't find any files to test")
}
for _, inputFile := range fileList {
patch, err := parsePatchFile(inputFile)
check(err)
file, err := ioutil.TempFile(os.TempDir(), "")
check(err)
info, err := file.Stat()
check(err)
outputFile := filepath.Join(os.TempDir(), info.Name())
patch.path = outputFile
err = writePatchFile(patch)
check(err)
input, err := ioutil.ReadFile(inputFile)
check(err)
output, err := ioutil.ReadFile(outputFile)
check(err)
err = os.Remove(patch.path)
check(err)
if !bytes.Equal(input, output) {
t.Errorf("Patch parser couldn't output file equal to input %q", inputFile)
}
}
}