-
Notifications
You must be signed in to change notification settings - Fork 58
/
file_unix_test.go
117 lines (95 loc) · 2.46 KB
/
file_unix_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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//go:build linux || darwin
// +build linux darwin
package kgo
import (
"github.com/stretchr/testify/assert"
"os"
"testing"
)
func TestFileUnix_IsReadable_Deny(t *testing.T) {
res := KFile.IsReadable(rootDir)
assert.False(t, res)
}
func TestFileUnix_IsWritable_Deny(t *testing.T) {
res := KFile.IsWritable(rootDir)
assert.False(t, res)
}
func TestFileUnix_IsExecutable_Deny(t *testing.T) {
var res bool
res = KFile.IsExecutable(rootDir)
assert.False(t, res)
}
func TestFileUnix_CopyFile_Deny(t *testing.T) {
var err error
//目标路径无权限
_, err = KFile.CopyFile(imgPng, rootFile1, FILE_COVER_ALLOW)
assert.NotNil(t, err)
}
func TestFileUnix_FastCopy_Deny(t *testing.T) {
var err error
//目录无权限
_, err = KFile.FastCopy(imgJpg, rootFile1)
assert.NotNil(t, err)
}
func TestFileUnix_CopyLink_Deny(t *testing.T) {
var err error
//创建链接文件
if !KFile.IsExist(fileLink) {
_ = os.Symlink(filePubPem, fileLink)
}
//目标路径无权限
err = KFile.CopyLink(fileLink, rootFile1, FILE_COVER_ALLOW)
assert.NotNil(t, err)
}
func TestFileUnix_CopyDir_Deny(t *testing.T) {
var err error
//目标路径无权限
_, err = KFile.CopyDir(dirVendor, rootDir2, FILE_COVER_ALLOW)
assert.NotNil(t, err)
//源路径无权限
_, err = KFile.CopyDir(rootDir, dirTdat, FILE_COVER_ALLOW)
assert.NotNil(t, err)
}
func TestFileUnix_DelDir_Deny(t *testing.T) {
var err error
//目录无权限
err = KFile.DelDir(rootDir, false)
assert.NotNil(t, err)
}
func TestFileUnix_TarGzUnTarGz(t *testing.T) {
var res bool
var err error
//打包-源目录无权限
res, err = KFile.TarGz(rootDir, targzfile2)
assert.False(t, res)
assert.NotNil(t, err)
//打包-目标目录无权限
res, err = KFile.TarGz(dirVendor, rootFile3)
assert.False(t, res)
assert.NotNil(t, err)
//解压到无权限的目录
if !KFile.IsExist(targzfile1) {
_, _ = KFile.TarGz(dirVendor, targzfile1)
}
res, err = KFile.UnTarGz(targzfile1, rootDir)
assert.False(t, res)
assert.NotNil(t, err)
}
func TestFileUnix_ChmodBatch(t *testing.T) {
var res bool
//无权限的目录
res = KFile.ChmodBatch(rootDir, 0777, 0777)
assert.False(t, res)
}
func TestFileUnix_ZipIszipUnzip(t *testing.T) {
var res1, res2 bool
var err1, err2 error
//打包无权限的目录
res1, err1 = KFile.Zip(zipfile2, rootDir)
assert.False(t, res1)
assert.NotNil(t, err1)
//解压到无权限的目录
res2, err2 = KFile.UnZip(zipfile1, rootDir)
assert.False(t, res2)
assert.NotNil(t, err2)
}