@@ -12,30 +12,10 @@ import (
12
12
13
13
// This file contains utilities for running tests around file system state.
14
14
15
- // fspath represents a file system path in an OS-agnostic way.
16
- type fsPath []string
17
-
18
- func (f fsPath ) String () string { return filepath .Join (f ... ) }
19
-
20
- func (f fsPath ) prepend (prefix string ) fsPath {
21
- p := fsPath {filepath .FromSlash (prefix )}
22
- return append (p , f ... )
23
- }
24
-
25
15
type fsTestCase struct {
26
16
before , after filesystemState
27
17
}
28
18
29
- // filesystemState represents the state of a file system. It has a setup method
30
- // which inflates its state to the actual host file system, and an assert
31
- // method which checks that the actual file system matches the described state.
32
- type filesystemState struct {
33
- root string
34
- dirs []fsPath
35
- files []fsPath
36
- links []fsLink
37
- }
38
-
39
19
// assert makes sure that the fs state matches the state of the actual host
40
20
// file system
41
21
func (fs filesystemState ) assert (t * testing.T ) {
@@ -44,13 +24,13 @@ func (fs filesystemState) assert(t *testing.T) {
44
24
linkMap := make (map [string ]bool )
45
25
46
26
for _ , d := range fs .dirs {
47
- dirMap [d . prepend (fs .root ). String ( )] = true
27
+ dirMap [filepath . Join (fs .root , d )] = true
48
28
}
49
29
for _ , f := range fs .files {
50
- fileMap [f . prepend (fs .root ). String ( )] = true
30
+ fileMap [filepath . Join (fs .root , f )] = true
51
31
}
52
32
for _ , l := range fs .links {
53
- linkMap [l . path . prepend (fs .root ). String ( )] = true
33
+ linkMap [filepath . Join (fs .root , l . path )] = true
54
34
}
55
35
56
36
err := filepath .Walk (fs .root , func (path string , info os.FileInfo , err error ) error {
@@ -106,12 +86,6 @@ func (fs filesystemState) assert(t *testing.T) {
106
86
}
107
87
}
108
88
109
- // fsLink represents a symbolic link.
110
- type fsLink struct {
111
- path fsPath
112
- to string
113
- }
114
-
115
89
// setup inflates fs onto the actual host file system
116
90
func (fs filesystemState ) setup (t * testing.T ) {
117
91
fs .setupDirs (t )
@@ -121,17 +95,17 @@ func (fs filesystemState) setup(t *testing.T) {
121
95
122
96
func (fs filesystemState ) setupDirs (t * testing.T ) {
123
97
for _ , dir := range fs .dirs {
124
- p := dir . prepend (fs .root )
125
- if err := os .MkdirAll (p . String () , 0777 ); err != nil {
98
+ p := filepath . Join (fs .root , dir )
99
+ if err := os .MkdirAll (p , 0777 ); err != nil {
126
100
t .Fatalf ("os.MkdirAll(%q, 0777) err=%q" , p , err )
127
101
}
128
102
}
129
103
}
130
104
131
105
func (fs filesystemState ) setupFiles (t * testing.T ) {
132
106
for _ , file := range fs .files {
133
- p := file . prepend (fs .root )
134
- f , err := os .Create (p . String () )
107
+ p := filepath . Join (fs .root , file )
108
+ f , err := os .Create (p )
135
109
if err != nil {
136
110
t .Fatalf ("os.Create(%q) err=%q" , p , err )
137
111
}
@@ -143,15 +117,15 @@ func (fs filesystemState) setupFiles(t *testing.T) {
143
117
144
118
func (fs filesystemState ) setupLinks (t * testing.T ) {
145
119
for _ , link := range fs .links {
146
- p := link . path . prepend (fs .root )
120
+ p := filepath . Join (fs .root , link . path )
147
121
148
122
// On Windows, relative symlinks confuse filepath.Walk. This is golang/go
149
123
// issue 17540. So, we'll just sigh and do absolute links, assuming they are
150
124
// relative to the directory of link.path.
151
- dir := filepath .Dir (p . String () )
125
+ dir := filepath .Dir (p )
152
126
to := filepath .Join (dir , link .to )
153
127
154
- if err := os .Symlink (to , p . String () ); err != nil {
128
+ if err := os .Symlink (to , p ); err != nil {
155
129
t .Fatalf ("os.Symlink(%q, %q) err=%q" , to , p , err )
156
130
}
157
131
}
0 commit comments