-
Notifications
You must be signed in to change notification settings - Fork 12
/
copy_win_test.go
64 lines (57 loc) · 1.63 KB
/
copy_win_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
// +build windows
package flop
import (
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"testing"
)
func TestForPresenceOfFileCopyErrors(t *testing.T) {
assert := assert.New(t)
tests := []struct {
name string
copyFunc func(string, os.FileInfo, string, os.FileInfo) error
inFile string
outFile string
errSubstringExpected string
}{
{
name: "src_path_which_cannot_be_opened",
inFile: "////",
outFile: tmpFile(),
errSubstringExpected: ErrCannotStatFile.Error(),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := SimpleCopy(tt.inFile, tt.outFile)
assert.True(errContains(err, tt.errSubstringExpected))
})
}
}
func TestFileCopyOnDstWithInvalidPermissionsReturnsAccessError(t *testing.T) {
assert := assert.New(t)
tests := []struct {
name string
opts Options
errSubstring string
}{
{"atomic", Options{Atomic: true}, ErrCannotRenameTempFile.Error()},
{"atomic", Options{Atomic: false}, ErrCannotOpenOrCreateDstFile.Error()},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// create and write to source inFile
src := tmpFile()
content := []byte("foo")
assert.Nil(ioutil.WriteFile(src, content, 0644))
dst := tmpFile()
// explicitly set our dst inFile perms so that we cannot copy
assert.Nil(os.Chmod(dst, 0111))
err := Copy(src, dst, tt.opts)
assert.True(errContains(err, tt.errSubstring), "err is: %s", err)
// change perms back to ensure we can read to verify content
assert.Nil(os.Chmod(dst, 0655))
})
}
}