-
Notifications
You must be signed in to change notification settings - Fork 53
/
fileutils_test.go
64 lines (50 loc) · 1.07 KB
/
fileutils_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
package hermit_test
import (
"archive/tar"
"compress/gzip"
"io"
"os"
"testing"
"time"
"github.com/alecthomas/assert/v2"
)
type TestTarGz struct {
files map[string]string
}
// StringFileInfo provides os.FileInfo implementation
type StringFileInfo struct {
name string
data string
}
func (targz *TestTarGz) Write(t *testing.T, w io.Writer) {
t.Helper()
gw := gzip.NewWriter(w)
defer gw.Close()
tw := tar.NewWriter(gw)
defer tw.Close()
for name, data := range targz.files {
header, _ := tar.FileInfoHeader(&StringFileInfo{name, data}, "")
err := tw.WriteHeader(header)
assert.NoError(t, err)
_, err = tw.Write([]byte(data))
assert.NoError(t, err)
}
}
func (info *StringFileInfo) Name() string {
return info.name
}
func (info *StringFileInfo) Size() int64 {
return int64(len([]byte(info.data)))
}
func (info *StringFileInfo) Mode() os.FileMode {
return os.ModePerm
}
func (info *StringFileInfo) ModTime() time.Time {
return time.Now()
}
func (info *StringFileInfo) IsDir() bool {
return false
}
func (info *StringFileInfo) Sys() interface{} {
return nil
}