forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs_test.go
64 lines (53 loc) · 1.38 KB
/
fs_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 fs
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/yaoapp/gou/fs"
"github.com/yaoapp/yao/config"
)
func TestLoad(t *testing.T) {
Load(config.Conf)
data := fs.MustGet("system")
size, err := fs.WriteFile(data, "test.file", []byte("Hi"), 0644)
assert.Nil(t, err)
assert.Equal(t, 2, size)
root, err := Root(config.Conf)
assert.Nil(t, err)
info, err := os.Stat(filepath.Join(root, "test.file"))
assert.Nil(t, err)
assert.Equal(t, int64(2), info.Size())
err = fs.Remove(data, "test.file")
if err != nil {
t.Fatal(err)
}
}
func TestDSL(t *testing.T) {
Load(config.Conf)
dsl := fs.MustGet("dsl")
name := filepath.Join("models", "test.mod.json")
_, err := fs.WriteFile(dsl, name, []byte(`{"foo": "bar", "hello":{ "int": 1, "float": 0.618}}`), 0644)
assert.Nil(t, err)
info, err := os.Stat(filepath.Join(config.Conf.Root, name))
assert.Nil(t, err)
assert.Equal(t, int64(69), info.Size())
dsl.Remove(name)
if err != nil {
t.Fatal(err)
}
}
func TestScirpt(t *testing.T) {
Load(config.Conf)
script := fs.MustGet("script")
name := "test.js"
_, err := fs.WriteFile(script, name, []byte(`console.log("hello")`), 0644)
assert.Nil(t, err)
info, err := os.Stat(filepath.Join(config.Conf.Root, "scripts", name))
assert.Nil(t, err)
assert.Equal(t, int64(20), info.Size())
script.Remove(name)
if err != nil {
t.Fatal(err)
}
}