-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathos_test.go
101 lines (76 loc) · 2.39 KB
/
os_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
// Copyright (c) 2015, Ben Morgan. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package osutil
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
const (
testfile = "testdata/random_a.dat"
testother = "testdata/random_b.dat"
testdest = "testdata/remove_me.dat"
)
func TestFileExists(z *testing.T) {
assert := assert.New(z)
ex, err := FileExists(testfile)
assert.Nil(err)
assert.True(ex, "expect file to exist", testfile)
ex, err = FileExists(testdest)
assert.Nil(err)
assert.False(ex, "expect file not to exist", testdest)
}
func TestSameFile(z *testing.T) {
assert := assert.New(z)
same, err := SameFile(testfile, testfile)
assert.Nil(err)
assert.True(same, "two same files should be the same", testfile)
same, err = SameFile(testfile, testother)
assert.Nil(err)
assert.False(same, "different files are not the same", testfile, testother)
err = CopyFile(testfile, testdest)
assert.Nil(err)
defer os.Remove(testdest)
same, err = SameFile(testfile, testdest)
assert.Nil(err)
assert.False(same, "different files with same contents not the same", testfile, testdest)
}
func TestSameContents(z *testing.T) {
assert := assert.New(z)
same, err := SameContents(testfile, testother)
assert.Nil(err)
assert.False(same, "different files not same contents", testfile, testother)
same, err = SameContents(testfile, testfile)
assert.Nil(err)
assert.True(same, "same file same contents", testfile)
err = CopyFile(testfile, testdest)
assert.Nil(err)
defer os.Remove(testdest)
same, err = SameContents(testfile, testdest)
assert.Nil(err)
assert.True(same, "copied file same contents", testfile, testdest)
}
func TestFileCopy(z *testing.T) {
assert := assert.New(z)
err := CopyFile(testfile, testdest)
assert.Nil(err)
defer os.Remove(testdest)
ex, err := FileExists(testdest)
assert.Nil(err)
assert.True(ex, "file should have been copied", testdest)
same, err := SameContents(testfile, testdest)
assert.Nil(err)
assert.True(same, "copied file should be same", testdest)
err = CopyFile(testother, testdest)
assert.Nil(err)
same, err = SameContents(testfile, testdest)
assert.Nil(err)
assert.False(same, "second copy should overwrite first")
}
func TestFileCopyLazy(z *testing.T) {
assert := assert.New(z)
err := CopyFileLazy(testfile, testdest)
assert.Nil(err)
defer os.Remove(testdest)
}