-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils_test.go
104 lines (92 loc) · 2.5 KB
/
utils_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
package iDB
import (
"os"
//"testing"
"io/ioutil"
. "github.com/snowyu/prettytest"
)
type UtilsTestSuite struct {
Suite
testfile string
}
func (suite *UtilsTestSuite) Before() {
suite.testfile = "mytestfile"
result, _ := FileIsExists(suite.testfile)
if !result {
ioutil.WriteFile(suite.testfile, nil, 0600)
}
suite.Path(suite.testfile)
}
func (suite *UtilsTestSuite) After() {
os.Remove(suite.testfile)
}
func (suite *UtilsTestSuite) doTestSetXattr(aKey, aValue string){
err := SetXattr(suite.testfile, aKey, aValue)
suite.Nil(err)
suite.True(IsXattrExists(suite.testfile, aKey))
suite.False(IsXattrExists(suite.testfile, aKey+".myNotExistsTheXKey"))
}
func (suite *UtilsTestSuite) TestSetXattr(){
suite.doTestSetXattr("mykey", "myvalue23")
suite.doTestSetXattr(".dsd.sd", "ajsae@3if34$/dsd")
}
func InStrings(aStr string, aList []string) bool {
result := false
for i := range aList {
if aList[i] == aStr {
result = true
break
}
}
return result
}
func (suite *UtilsTestSuite) TestListXattr(){
pairs := map[string]string {
"mykey": "myvalue23",
"mykey2":"ajsae@3if34$/dsd",
}
for k,v := range pairs {
suite.doTestSetXattr(k, v)
}
names, err := ListXattr(suite.testfile)
suite.Nil(err)
for k := range pairs {
suite.True(InStrings(k, names))
}
}
func (suite *UtilsTestSuite) TestGetXatrr(){
//suite.TestSetXattr()
suite.doTestSetXattr("mykey", "myvalue23")
pairs := map[string]string {
"mykey": "myvalue23",
"mykey2":"ajsae@3if34$/dsd",
}
var result string
var err error
for k,v := range pairs {
suite.doTestSetXattr(k, v)
result, err = GetXattr(suite.testfile, k)
suite.Nil(err)
suite.Equal(result, v)
}
result, err = GetXattr(suite.testfile, "myNotExistsTheXKey")
suite.NotNil(err)
suite.Equal(result, "")
}
func (suite *UtilsTestSuite) TestDeleteXatrr(){
//suite.TestSetXattr()
suite.doTestSetXattr("mykey", "myvalue23")
err := DeleteXattr(suite.testfile, "mykey")
suite.Nil(err)
suite.False(IsXattrExists(suite.testfile, "mykey"))
err = DeleteXattr(suite.testfile, "myNotExistsTheXKey")
suite.NotNil(err)
}
func (suite *UtilsTestSuite) TestFileIsExists(){
result, err := FileIsExists(suite.testfile)
suite.True(result)
suite.Nil(err)
result, err = FileIsExists("#.NoSuchFileExists##!!")
suite.False(result)
suite.Nil(err)
}