-
Notifications
You must be signed in to change notification settings - Fork 14
/
functions.go
68 lines (60 loc) · 1.8 KB
/
functions.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 helpers
import (
"fmt"
"io/ioutil"
"path/filepath"
"runtime"
"testing"
"github.com/stretchr/testify/require"
)
func ReadFixture(filename string) ([]byte, error) {
_, thisFile, _, ok := runtime.Caller(0)
if ok {
return ioutil.ReadFile(filepath.Join(filepath.Dir(thisFile), "..", "fixtures", filename))
} else {
return []byte{}, fmt.Errorf("cannot find the functions.go file in your filepath")
}
}
// func ReadDocument(t *testing.T, filename string) *meta.Document {
// docRaw, err := ReadFixture(filename)
// require.NoError(t, err)
// doc := &meta.Document{
// Meta: &meta.Meta{
// Name: filename,
// },
// Data: docRaw,
// }
// switch filepath.Ext(filename) {
// case ".docx":
// doc.Meta.MimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
// case ".md":
// doc.Meta.MimeType = "text/markdown"
// case ".html":
// doc.Meta.MimeType = "text/html"
// case ".json":
// doc.Meta.MimeType = "application/json"
// case ".pdf":
// doc.Meta.MimeType = "application/pdf"
// case ".rtf":
// doc.Meta.MimeType = "application/rtf"
// case ".doc":
// doc.Meta.MimeType = "application/msword"
// case ".odt":
// doc.Meta.MimeType = "application/vnd.oasis.opendocument.text"
// }
// return doc
// }
func WriteResult(t *testing.T, data []byte) {
_, thisFile, _, ok := runtime.Caller(0)
if ok {
err := ioutil.WriteFile(filepath.Join(filepath.Dir(thisFile), "..", "results", fmt.Sprintf("Result_%s.docx", t.Name())), data, 0644)
require.NoError(t, err)
}
}
func WriteResultWithExt(t *testing.T, data []byte, postfix string) {
_, thisFile, _, ok := runtime.Caller(0)
if ok {
err := ioutil.WriteFile(filepath.Join(filepath.Dir(thisFile), "..", "results", fmt.Sprintf("Result_%s_%s", t.Name(), postfix)), data, 0644)
require.NoError(t, err)
}
}