-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlocation_file_test.go
48 lines (42 loc) · 1.23 KB
/
location_file_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
package tmpl
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestBuildFileLocation(t *testing.T) {
ok := []string{
"file:///foo.txt",
// TODO: "/foo.txt",
}
notOk := []string{
"-",
"http://foo.tld/",
"shell://foo.tld/",
"/foo\n.txt",
}
for _, loc := range ok {
assert.NotNil(t, BuildFileLocation(loc), fmt.Sprintf("File location build from \"%s\"", loc))
}
for _, loc := range notOk {
assert.Nil(t, BuildFileLocation(loc), fmt.Sprintf("File location NOT build from \"%s\"", loc))
}
}
func TestFileLocation_Load(t *testing.T) {
fs := FileLocation("./location.go")
raw, err := fs.Load()
assert.Nil(t, err, "No load error")
assert.Contains(t, string(raw), "package tmpl", "File was loaded")
}
func TestFileLocation_Load_FromFileSchema(t *testing.T) {
fs := FileLocation("file://./location.go")
raw, err := fs.Load()
assert.Nil(t, err, "No load error")
assert.Contains(t, string(raw), "package tmpl", "File was loaded")
}
func TestFileLocation_Load_FailFromNoFile(t *testing.T) {
fs := FileLocation("not-existing-file")
_, err := fs.Load()
assert.NotNil(t, err, "No throw error")
assert.Contains(t, err.Error(), "open not-existing-file: no such file or directory", "Should remark does not exists")
}