@@ -83,41 +83,6 @@ func TestCopy(t *testing.T) {
8383 Expect (t , info .Mode ()& os .ModeSymlink ).Not ().ToBe (0 )
8484 })
8585
86- When (t , "symlink with Opt.OnSymlink provided" , func (t * testing.T ) {
87- opt := Options {OnSymlink : func (string ) SymlinkAction { return Deep }}
88- err := Copy ("testdata/case03" , "testdata.copy/case03.deep" , opt )
89- Expect (t , err ).ToBe (nil )
90- info , err := os .Lstat ("testdata.copy/case03.deep/case01" )
91- Expect (t , err ).ToBe (nil )
92- Expect (t , info .Mode ()& os .ModeSymlink ).ToBe (os .FileMode (0 ))
93-
94- opt = Options {OnSymlink : func (string ) SymlinkAction { return Shallow }}
95- err = Copy ("testdata/case03" , "testdata.copy/case03.shallow" , opt )
96- Expect (t , err ).ToBe (nil )
97- info , err = os .Lstat ("testdata.copy/case03.shallow/case01" )
98- Expect (t , err ).ToBe (nil )
99- Expect (t , info .Mode ()& os .ModeSymlink ).Not ().ToBe (os .FileMode (0 ))
100-
101- opt = Options {OnSymlink : func (string ) SymlinkAction { return Skip }}
102- err = Copy ("testdata/case03" , "testdata.copy/case03.skip" , opt )
103- Expect (t , err ).ToBe (nil )
104- _ , err = os .Stat ("testdata.copy/case03.skip/case01" )
105- Expect (t , os .IsNotExist (err )).ToBe (true )
106-
107- err = Copy ("testdata/case03" , "testdata.copy/case03.default" )
108- Expect (t , err ).ToBe (nil )
109- info , err = os .Lstat ("testdata.copy/case03.default/case01" )
110- Expect (t , err ).ToBe (nil )
111- Expect (t , info .Mode ()& os .ModeSymlink ).Not ().ToBe (os .FileMode (0 ))
112-
113- opt = Options {OnSymlink : nil }
114- err = Copy ("testdata/case03" , "testdata.copy/case03.not-specified" , opt )
115- Expect (t , err ).ToBe (nil )
116- info , err = os .Lstat ("testdata.copy/case03.not-specified/case01" )
117- Expect (t , err ).ToBe (nil )
118- Expect (t , info .Mode ()& os .ModeSymlink ).Not ().ToBe (os .FileMode (0 ))
119- })
120-
12186 When (t , "try to copy to an existing path" , func (t * testing.T ) {
12287 err := Copy ("testdata/case03" , "testdata.copy/case03" )
12388 Expect (t , err ).Not ().ToBe (nil )
@@ -149,103 +114,136 @@ func TestCopy(t *testing.T) {
149114 Expect (t , err ).ToBe (nil )
150115 })
151116
152- When (t , "Options.Skip provided" , func (t * testing.T ) {
153- opt := Options {Skip : func (src string ) (bool , error ) {
154- switch {
155- case strings .HasSuffix (src , "_skip" ):
156- return true , nil
157- case strings .HasSuffix (src , ".gitfake" ):
158- return true , nil
159- default :
160- return false , nil
161- }
162- }}
163- err := Copy ("testdata/case06" , "testdata.copy/case06" , opt )
164- Expect (t , err ).ToBe (nil )
165- info , err := os .Stat ("./testdata.copy/case06/dir_skip" )
166- Expect (t , info ).ToBe (nil )
167- Expect (t , os .IsNotExist (err )).ToBe (true )
117+ }
168118
169- info , err = os .Stat ("./testdata.copy/case06/file_skip" )
170- Expect (t , info ).ToBe (nil )
171- Expect (t , os .IsNotExist (err )).ToBe (true )
119+ func TestOptions_OnSymlink (t * testing.T ) {
120+ opt := Options {OnSymlink : func (string ) SymlinkAction { return Deep }}
121+ err := Copy ("testdata/case03" , "testdata.copy/case03.deep" , opt )
122+ Expect (t , err ).ToBe (nil )
123+ info , err := os .Lstat ("testdata.copy/case03.deep/case01" )
124+ Expect (t , err ).ToBe (nil )
125+ Expect (t , info .Mode ()& os .ModeSymlink ).ToBe (os .FileMode (0 ))
172126
173- info , err = os .Stat ("./testdata.copy/case06/README.md" )
174- Expect (t , info ).Not ().ToBe (nil )
175- Expect (t , err ).ToBe (nil )
127+ opt = Options {OnSymlink : func (string ) SymlinkAction { return Shallow }}
128+ err = Copy ("testdata/case03" , "testdata.copy/case03.shallow" , opt )
129+ Expect (t , err ).ToBe (nil )
130+ info , err = os .Lstat ("testdata.copy/case03.shallow/case01" )
131+ Expect (t , err ).ToBe (nil )
132+ Expect (t , info .Mode ()& os .ModeSymlink ).Not ().ToBe (os .FileMode (0 ))
176133
177- info , err = os .Stat ("./testdata.copy/case06/repo/.gitfake" )
178- Expect (t , info ).ToBe (nil )
179- Expect (t , os .IsNotExist (err )).ToBe (true )
134+ opt = Options {OnSymlink : func (string ) SymlinkAction { return Skip }}
135+ err = Copy ("testdata/case03" , "testdata.copy/case03.skip" , opt )
136+ Expect (t , err ).ToBe (nil )
137+ _ , err = os .Stat ("testdata.copy/case03.skip/case01" )
138+ Expect (t , os .IsNotExist (err )).ToBe (true )
180139
181- info , err = os .Stat ("./testdata.copy/case06/repo/README.md" )
182- Expect (t , info ).Not ().ToBe (nil )
183- Expect (t , err ).ToBe (nil )
140+ err = Copy ("testdata/case03" , "testdata.copy/case03.default" )
141+ Expect (t , err ).ToBe (nil )
142+ info , err = os .Lstat ("testdata.copy/case03.default/case01" )
143+ Expect (t , err ).ToBe (nil )
144+ Expect (t , info .Mode ()& os .ModeSymlink ).Not ().ToBe (os .FileMode (0 ))
184145
185- Because (t , "if Skip func returns error, Copy should be interrupted" , func (t * testing.T ) {
186- errInsideSkipFunc := errors .New ("Something wrong inside Skip" )
187- opt := Options {Skip : func (src string ) (bool , error ) {
188- return false , errInsideSkipFunc
189- }}
190- err := Copy ("testdata/case06" , "testdata.copy/case06.01" , opt )
191- Expect (t , err ).ToBe (errInsideSkipFunc )
192- files , err := ioutil .ReadDir ("./testdata.copy/case06.01" )
193- Expect (t , err ).ToBe (nil )
194- Expect (t , len (files )).ToBe (0 )
195- })
196- })
146+ opt = Options {OnSymlink : nil }
147+ err = Copy ("testdata/case03" , "testdata.copy/case03.not-specified" , opt )
148+ Expect (t , err ).ToBe (nil )
149+ info , err = os .Lstat ("testdata.copy/case03.not-specified/case01" )
150+ Expect (t , err ).ToBe (nil )
151+ Expect (t , info .Mode ()& os .ModeSymlink ).Not ().ToBe (os .FileMode (0 ))
152+ }
197153
198- When (t , "Options.AddPermission provided" , func (t * testing.T ) {
154+ func TestOptions_Skip (t * testing.T ) {
155+ opt := Options {Skip : func (src string ) (bool , error ) {
156+ switch {
157+ case strings .HasSuffix (src , "_skip" ):
158+ return true , nil
159+ case strings .HasSuffix (src , ".gitfake" ):
160+ return true , nil
161+ default :
162+ return false , nil
163+ }
164+ }}
165+ err := Copy ("testdata/case06" , "testdata.copy/case06" , opt )
166+ Expect (t , err ).ToBe (nil )
167+ info , err := os .Stat ("./testdata.copy/case06/dir_skip" )
168+ Expect (t , info ).ToBe (nil )
169+ Expect (t , os .IsNotExist (err )).ToBe (true )
199170
200- info , err : = os .Stat ("testdata/case07/dir_0500 " )
201- Expect (t , err ).ToBe (nil )
202- Expect (t , info . Mode ( )).ToBe (os . FileMode ( 0500 ) | os . ModeDir )
171+ info , err = os .Stat ("./ testdata.copy/case06/file_skip " )
172+ Expect (t , info ).ToBe (nil )
173+ Expect (t , os . IsNotExist ( err )).ToBe (true )
203174
204- info , err = os .Stat ("testdata/case07/file_0444 " )
205- Expect (t , err ).ToBe (nil )
206- Expect (t , info . Mode ()) .ToBe (os . FileMode ( 0444 ) )
175+ info , err = os .Stat ("./ testdata.copy/case06/README.md " )
176+ Expect (t , info ). Not ( ).ToBe (nil )
177+ Expect (t , err ) .ToBe (nil )
207178
208- opt := Options { AddPermission : 0200 }
209- err = Copy ( "testdata/case07" , "testdata.copy/case07" , opt )
210- Expect (t , err ).ToBe (nil )
179+ info , err = os . Stat ( "./testdata.copy/case06/repo/.gitfake" )
180+ Expect ( t , info ). ToBe ( nil )
181+ Expect (t , os . IsNotExist ( err )) .ToBe (true )
211182
212- info , err = os .Stat ("testdata.copy/case07/dir_0500 " )
213- Expect (t , err ).ToBe (nil )
214- Expect (t , info . Mode ()) .ToBe (os . FileMode ( 0500 | 0200 ) | os . ModeDir )
183+ info , err = os .Stat ("./ testdata.copy/case06/repo/README.md " )
184+ Expect (t , info ). Not ( ).ToBe (nil )
185+ Expect (t , err ) .ToBe (nil )
215186
216- info , err = os .Stat ("testdata.copy/case07/file_0444" )
187+ Because (t , "if Skip func returns error, Copy should be interrupted" , func (t * testing.T ) {
188+ errInsideSkipFunc := errors .New ("Something wrong inside Skip" )
189+ opt := Options {Skip : func (src string ) (bool , error ) {
190+ return false , errInsideSkipFunc
191+ }}
192+ err := Copy ("testdata/case06" , "testdata.copy/case06.01" , opt )
193+ Expect (t , err ).ToBe (errInsideSkipFunc )
194+ files , err := ioutil .ReadDir ("./testdata.copy/case06.01" )
217195 Expect (t , err ).ToBe (nil )
218- Expect (t , info . Mode ( )).ToBe (os . FileMode ( 0444 | 0200 ) )
196+ Expect (t , len ( files )).ToBe (0 )
219197 })
198+ }
220199
221- When (t , "Options.Sync provided" , func (t * testing.T ) {
222- // With Sync option, each file will be flushed to storage on copying.
223- // TODO: Since it's a bit hard to simulate real usecases here. This testcase is nonsense.
224- opt := Options {Sync : true }
225- err = Copy ("testdata/case08" , "testdata.copy/case08" , opt )
226- Expect (t , err ).ToBe (nil )
227- })
200+ func TestOptions_AddPermission (t * testing.T ) {
201+ info , err := os .Stat ("testdata/case07/dir_0500" )
202+ Expect (t , err ).ToBe (nil )
203+ Expect (t , info .Mode ()).ToBe (os .FileMode (0500 ) | os .ModeDir )
228204
229- When (t , "Options.PreserveTimes provided" , func (t * testing.T ) {
205+ info , err = os .Stat ("testdata/case07/file_0444" )
206+ Expect (t , err ).ToBe (nil )
207+ Expect (t , info .Mode ()).ToBe (os .FileMode (0444 ))
230208
231- err = Copy ("testdata/case09" , "testdata.copy/case09" )
232- Expect (t , err ).ToBe (nil )
233- opt := Options {PreserveTimes : true }
234- err = Copy ("testdata/case09" , "testdata.copy/case09-preservetimes" , opt )
235- Expect (t , err ).ToBe (nil )
209+ opt := Options {AddPermission : 0200 }
210+ err = Copy ("testdata/case07" , "testdata.copy/case07" , opt )
211+ Expect (t , err ).ToBe (nil )
236212
237- for _ , entry := range []string {"" , "README.md" , "symlink" } {
238- orig , err := os .Stat ("testdata/case09/" + entry )
239- Expect (t , err ).ToBe (nil )
240- plain , err := os .Stat ("testdata.copy/case09/" + entry )
241- Expect (t , err ).ToBe (nil )
242- preserved , err := os .Stat ("testdata.copy/case09-preservetimes/" + entry )
243- Expect (t , err ).ToBe (nil )
244- Expect (t , plain .ModTime ().Unix ()).Not ().ToBe (orig .ModTime ().Unix ())
245- Expect (t , preserved .ModTime ().Unix ()).ToBe (orig .ModTime ().Unix ())
246- }
213+ info , err = os .Stat ("testdata.copy/case07/dir_0500" )
214+ Expect (t , err ).ToBe (nil )
215+ Expect (t , info .Mode ()).ToBe (os .FileMode (0500 | 0200 ) | os .ModeDir )
247216
248- })
217+ info , err = os .Stat ("testdata.copy/case07/file_0444" )
218+ Expect (t , err ).ToBe (nil )
219+ Expect (t , info .Mode ()).ToBe (os .FileMode (0444 | 0200 ))
220+ }
221+
222+ func TestOptions_Sync (t * testing.T ) {
223+ // With Sync option, each file will be flushed to storage on copying.
224+ // TODO: Since it's a bit hard to simulate real usecases here. This testcase is nonsense.
225+ opt := Options {Sync : true }
226+ err := Copy ("testdata/case08" , "testdata.copy/case08" , opt )
227+ Expect (t , err ).ToBe (nil )
228+ }
229+
230+ func TestOptions_PreserveTimes (t * testing.T ) {
231+ err := Copy ("testdata/case09" , "testdata.copy/case09" )
232+ Expect (t , err ).ToBe (nil )
233+ opt := Options {PreserveTimes : true }
234+ err = Copy ("testdata/case09" , "testdata.copy/case09-preservetimes" , opt )
235+ Expect (t , err ).ToBe (nil )
236+
237+ for _ , entry := range []string {"" , "README.md" , "symlink" } {
238+ orig , err := os .Stat ("testdata/case09/" + entry )
239+ Expect (t , err ).ToBe (nil )
240+ plain , err := os .Stat ("testdata.copy/case09/" + entry )
241+ Expect (t , err ).ToBe (nil )
242+ preserved , err := os .Stat ("testdata.copy/case09-preservetimes/" + entry )
243+ Expect (t , err ).ToBe (nil )
244+ Expect (t , plain .ModTime ().Unix ()).Not ().ToBe (orig .ModTime ().Unix ())
245+ Expect (t , preserved .ModTime ().Unix ()).ToBe (orig .ModTime ().Unix ())
246+ }
249247}
250248
251249func TestOptions_OnDirExists (t * testing.T ) {
0 commit comments