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
|
package oss
import (
"math"
"net/http"
. "gopkg.in/check.v1"
)
type OssErrorSuite struct{}
var _ = Suite(&OssErrorSuite{})
func (s *OssErrorSuite) TestCheckCRCHasCRCInResp(c *C) {
headers := http.Header{
"Expires": {"-1"},
"Content-Length": {"0"},
"Content-Encoding": {"gzip"},
"X-Oss-Hash-Crc64ecma": {"0"},
}
resp := &Response{
StatusCode: 200,
Headers: headers,
Body: nil,
ClientCRC: math.MaxUint64,
ServerCRC: math.MaxUint64,
}
err := checkCRC(resp, "test")
c.Assert(err, IsNil)
}
func (s *OssErrorSuite) TestCheckCRCNotHasCRCInResp(c *C) {
headers := http.Header{
"Expires": {"-1"},
"Content-Length": {"0"},
"Content-Encoding": {"gzip"},
}
resp := &Response{
StatusCode: 200,
Headers: headers,
Body: nil,
ClientCRC: math.MaxUint64,
ServerCRC: math.MaxUint32,
}
err := checkCRC(resp, "test")
c.Assert(err, IsNil)
}
func (s *OssErrorSuite) TestCheckCRCCNegative(c *C) {
headers := http.Header{
"Expires": {"-1"},
"Content-Length": {"0"},
"Content-Encoding": {"gzip"},
"X-Oss-Hash-Crc64ecma": {"0"},
}
resp := &Response{
StatusCode: 200,
Headers: headers,
Body: nil,
ClientCRC: 0,
ServerCRC: math.MaxUint64,
}
err := checkCRC(resp, "test")
c.Assert(err, NotNil)
testLogger.Println("error:", err)
}
|