-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathutil_test.go
98 lines (76 loc) · 2.13 KB
/
util_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package diecast
import (
"net/http"
"os"
"testing"
"github.com/ghetzel/go-stockutil/fileutil"
"github.com/ghetzel/testify/require"
)
func TestFancyMapJoin(t *testing.T) {
var assert = require.New(t)
assert.Equal(`hello=there`, fancyMapJoin(map[string]interface{}{
`hello`: `there`,
}))
assert.Equal(`hello=there&how=are you?`, fancyMapJoin(map[string]interface{}{
`hello`: `there`,
`how`: `are you?`,
}))
assert.Equal(`hello: there; how: are you?`, fancyMapJoin(map[string]interface{}{
`_kvjoin`: `: `,
`_join`: `; `,
`hello`: `there`,
`how`: `are you?`,
}))
assert.Equal(`hello: "there"; how: "are you?"`, fancyMapJoin(map[string]interface{}{
`_kvjoin`: `: `,
`_join`: `; `,
`_vformat`: "%q",
`hello`: `there`,
`how`: `are you?`,
}))
}
func TestZipFS(t *testing.T) {
var file http.File
var stat os.FileInfo
var fs, err = newZipFsFromFile(`./tests/zip-fs-test.zip`)
require.NoError(t, err)
require.NotNil(t, fs)
file, err = fs.Open(`/`)
require.NoError(t, err)
stat, err = file.Stat()
require.NoError(t, err)
require.True(t, stat.IsDir())
file, err = fs.Open(`README.md`)
require.NoError(t, err)
require.Contains(t, fileutil.Cat(file), `ZIPFS TEST`)
// ===================================================================================================================
var entries []string
for _, entry := range fs.entries(`/`) {
entries = append(entries, entry.Name())
}
require.Equal(t, []string{
"subdir",
"README.md",
}, entries)
// ===================================================================================================================
entries = nil
for _, entry := range fs.entries(`subdir`) {
entries = append(entries, entry.Name())
}
require.Equal(t, []string{
"more",
"third.txt",
"first.txt",
"second.txt",
}, entries)
// ===================================================================================================================
entries = nil
for _, entry := range fs.entries(`subdir/more`) {
entries = append(entries, entry.Name())
}
require.Equal(t, []string{
"even-more",
"fourth.txt",
"fifth.txt",
}, entries)
}