This repository has been archived by the owner on Jul 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
fs_test.go
112 lines (91 loc) · 2.32 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
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
106
107
108
109
110
111
112
package gas
import (
"os"
"testing"
)
func TestAbs(t *testing.T) {
fs := UnitedFS()
abs, err := fs.Abs("github.com/andrebq/gas/fs.go", false)
if err != nil {
t.Fatalf("Should have found the fs.go file. But got: %v", err)
}
if abs == "" {
t.Fatalf("abs should have a valid path inside of it")
}
info, err := os.Stat(abs)
if err != nil {
t.Fatalf("os.Stat returned a error: %v", err)
}
if info.IsDir() {
t.Fatalf("abs is pointing to a directory: (%v)", abs)
}
abs, err = fs.Abs("fs.go", false)
if err != nil {
t.Fatalf("Should have found the fs.go file. But got: %v", err)
}
if abs == "" {
t.Fatalf("abs should have a valid path inside of it")
}
info, err = os.Stat(abs)
if err != nil {
t.Fatalf("os.Stat returned a error: %v", err)
}
if info.IsDir() {
t.Fatalf("abs is pointing to a directory: (%v)", abs)
}
}
func TestAbsDir(t *testing.T) {
fs := UnitedFS()
abs, err := fs.Abs("github.com/andrebq/gas/", true)
if err != nil {
t.Fatalf("Should have found the gas directory. But got: %v", err)
}
if abs == "" {
t.Fatalf("abs should have a valid path inside of it")
}
info, err := os.Stat(abs)
if err != nil {
t.Fatalf("os.Stat returned a error: %v", err)
}
if !info.IsDir() {
t.Fatalf("abs isn't pointing to a directory: (%v)", abs)
}
abs, err = fs.Abs("../gas", true)
if err != nil {
t.Fatalf("Shoudl have found the ../gas directory. But got: %v", err)
}
if abs == "" {
t.Fatalf("abs should have a valid path inside of it")
}
info, err = os.Stat(abs)
if err != nil {
t.Fatalf("os.Stat returned a error: %v", err)
}
}
func TestOpen(t *testing.T) {
fs := UnitedFS()
file, err := fs.Open("github.com/andrebq/gas/fs.go")
if err != nil {
t.Fatalf("Unable to open fs.go file. %v", err)
}
file.Close()
file, err = fs.Open("fs.go") // should find the file using the "." path
if err != nil {
t.Fatalf("Unable to open fs.go (using local folder). %v", err)
}
file.Close()
}
func TestFromDirs(t *testing.T) {
ufs := UnitedFS()
gasDir, err := ufs.Abs("github.com/gas", true)
dirfs := FromDirs([]string{gasDir})
// since I added github.com/gas as a directory using
// unitedfs
// the dirfs should be able to find the fs.go file
// without any prefix
file, err := dirfs.Open("fs.go")
if err != nil {
t.Fatalf("should have found the fs.go file")
}
defer file.Close()
}