forked from aliyun/aliyun-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash_test.go
81 lines (66 loc) · 1.98 KB
/
hash_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
package lib
import (
. "gopkg.in/check.v1"
"os"
)
func (s *OssutilCommandSuite) TestErrorInputFile(c *C) {
command := "hash"
fakeFileName := randStr(10)
args := []string{fakeFileName}
hashType := DefaultHashType
options := OptionMapType{
"hash": &hashType,
}
showElapse, err := cm.RunCommand(command, args, options)
c.Assert(err, NotNil)
c.Assert(showElapse, Equals, false)
}
func (s *OssutilCommandSuite) TestErrorHashType(c *C) {
command := "hash"
hashType := "crc256"
fakeFileName := randStr(10)
args := []string{fakeFileName}
options := OptionMapType{
"hashType": &hashType,
}
showElapse, err := cm.RunCommand(command, args, options)
c.Assert(err, NotNil)
c.Assert(showElapse, Equals, false)
}
func (s *OssutilCommandSuite) TestCrc64(c *C) {
command := "hash"
content = "this is content"
s.createFile(inputFileName, content, c)
args := []string{inputFileName}
hashType := DefaultHashType
options := OptionMapType{
"hashType": &hashType,
}
testResultFile, _ = os.OpenFile(resultPath, os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0664)
os.Stdout = testResultFile
showElapse, err := cm.RunCommand(command, args, options)
c.Assert(err, IsNil)
c.Assert(showElapse, Equals, false)
hashStat := s.getHashResults(c)
c.Assert(hashStat[HashCRC64], Equals, "2863152195715871371")
os.Remove(inputFileName)
}
func (s *OssutilCommandSuite) TestMd5(c *C) {
command := "hash"
content = "this is content"
s.createFile(inputFileName, content, c)
args := []string{inputFileName}
hashType := MD5HashType
options := OptionMapType{
"hashType": &hashType,
}
testResultFile, _ = os.OpenFile(resultPath, os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0664)
os.Stdout = testResultFile
showElapse, err := cm.RunCommand(command, args, options)
c.Assert(err, IsNil)
c.Assert(showElapse, Equals, false)
hashStat := s.getHashResults(c)
c.Assert(hashStat[HashMD5], Equals, "B7FCEF7FE745F2A95560FF5F550E3B8F")
c.Assert(hashStat[HashContentMD5], Equals, "t/zvf+dF8qlVYP9fVQ47jw==")
os.Remove(inputFileName)
}