-
Notifications
You must be signed in to change notification settings - Fork 4
/
manifest_test.go
105 lines (88 loc) · 2.64 KB
/
manifest_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
99
100
101
102
103
104
105
package main
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
var testarea = filepath.Join(cwd(), "testarea")
func TestRenderFileTemplate(t *testing.T) {
Assert(t, RenderFileTemplate(
"userChrome.css",
"linux",
Variant{},
map[string]string{},
), "userChrome.css")
Assert(t, RenderFileTemplate(
"linux.css",
"linux",
Variant{},
map[string]string{"linux": "Linux"},
), "linux.css")
Assert(t, RenderFileTemplate(
"{{os}}.css",
"linux",
Variant{},
map[string]string{"linux": "GNU/Linux"},
), "GNU/Linux.css")
Assert(t, RenderFileTemplate(
"linux.css",
"windows",
Variant{},
map[string]string{},
), "linux.css")
Assert(t, RenderFileTemplate(
"./{{ os }}/{{variant}}.css",
"macos",
Variant{Name: "rainbow"},
map[string]string{},
), "./macos/rainbow.css")
}
func TestAssetsPaths(t *testing.T) {
simplerentfox := Manifest{
ExplicitName: "simplerentfox",
Variants: map[string]Variant{
"WithoutURLBar": {},
"OneLine": {},
},
Assets: []string{"./{{ os }}/userChrome__{{ variant }}.css"}, // for the purposes of testing
OSNames: map[string]string{
"linux": "Linux",
"macos": "Linux",
"windows": "Windows",
},
}
files, err := simplerentfox.AssetsPaths("linux", Variant{Name: "blue"}, testarea)
assert.Regexp(t, "file .+ not found", err.Error())
assert.Equal(t, []string{}, files)
files, err = simplerentfox.AssetsPaths("linux", Variant{Name: "OneLine"}, testarea)
assert.NoError(t, err)
assert.Equal(t, []string{CacheDir("simplerentfox/Linux/userChrome__OneLine.css")}, files)
}
func TestDestinationPathOf(t *testing.T) {
manifest := Manifest{
ExplicitName: "materialfox",
Variants: map[string]Variant{},
Config: Config{},
}
file, err := manifest.DestinationPathOfAsset("/home/ewen/lol.pdf", testarea, "linux", Variant{})
if assert.Error(t, err) {
assert.Regexp(t, `asset ".+" is outside of the theme's root ".+"`, err.Error())
}
assert.Equal(t, "", file)
file, err = manifest.DestinationPathOfAsset("/home/.cache/ffcss/simplerentfox/../../../lol.pdf", testarea, "linux", Variant{})
if assert.Error(t, err) {
assert.Regexp(t, `asset ".+" is outside of the theme's root ".+"`, err.Error())
}
assert.Equal(t, "", file)
manifest = Manifest{
ExplicitName: "simplerentfox",
Variants: map[string]Variant{
"WithoutURLBar": {},
"OneLine": {},
},
CopyFrom: "{{ os }}/",
}
file, err = manifest.DestinationPathOfAsset(CacheDir("simplerentfox/linux/userChrome__OneLine.css"), testarea, "linux", Variant{Name: "OneLine"})
assert.NoError(t, err)
assert.Equal(t, filepath.Join(testarea, "chrome", "userChrome__OneLine.css"), file)
}