forked from baltimore-sun-data/csv2json
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv2json_test.go
More file actions
62 lines (50 loc) · 1.28 KB
/
Copy pathcsv2json_test.go
File metadata and controls
62 lines (50 loc) · 1.28 KB
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
package main
import (
"crypto/md5"
"encoding/hex"
"io"
"os"
"testing"
"github.com/dstull/csv2json/model"
)
func TestCanConverFile(t *testing.T) {
args := []string{"-i=testdata/test.csv", "-o=testdata/tmp/test.json"}
_, err := model.FromArgs(args)
if err != nil {
t.Error("Failed to process arguments")
}
}
func TestMainProgram(t *testing.T) {
goldenFile := "testdata/test.json"
outputFile := "testdata/tmp/test_main.json"
os.Args = []string{"bogus",
"-i=testdata/test.csv",
"-o=testdata/tmp/test_main.json"}
main()
goldenFileMD5, err := hash_file_md5(goldenFile)
if err != nil {
t.Errorf("Failed to get md5 sum of %v", goldenFile)
}
outputFileMD5, err := hash_file_md5(outputFile)
if err != nil {
t.Errorf("Failed to get md5 sum of %v", outputFile)
}
if goldenFileMD5 != outputFileMD5 {
t.Errorf("Checksum of %v does not match %v", outputFile, goldenFile)
}
}
func hash_file_md5(filePath string) (string, error) {
var returnMD5String string
file, err := os.Open(filePath)
if err != nil {
return returnMD5String, err
}
defer file.Close()
hash := md5.New()
if _, err := io.Copy(hash, file); err != nil {
return returnMD5String, err
}
hashInBytes := hash.Sum(nil)[:16]
returnMD5String = hex.EncodeToString(hashInBytes)
return returnMD5String, nil
}