-
Notifications
You must be signed in to change notification settings - Fork 44
/
util_test.go
66 lines (40 loc) · 1.07 KB
/
util_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
package envplate
import (
"testing"
"github.com/stretchr/testify/assert"
)
const (
testBackupFile = "test/filemode.txt.bak"
testFile = "test/filemode.txt"
)
func TestBackup(t *testing.T) {
defer _delete(t, testBackupFile)
assert := assert.New(t)
modeBackup, err := filemode(testBackupFile)
assert.Error(err)
modeFile, err := filemode(testFile)
assert.NoError(err)
assert.Equal("hello world\n", _read(t, testFile))
assert.NoError(createBackup(testFile))
modeBackup, err = filemode(testBackupFile)
assert.NoError(err)
modeFile, err = filemode(testFile)
assert.NoError(err)
assert.Equal(modeBackup.String(), modeFile.String())
assert.Equal(_read(t, testFile), _read(t, testBackupFile))
}
func TestBackupErrors(t *testing.T) {
assert := assert.New(t)
_tmpdir(t, func(dir string) {
err := createBackup(dir)
assert.Error(err)
})
}
func TestFilemode(t *testing.T) {
assert := assert.New(t)
mode, err := filemode(testFile)
assert.NoError(err)
assert.Equal("-rwxrw-r-x", mode.String())
mode, err = filemode("test/nofile.txt")
assert.Error(err)
}