|
|
@@ -0,0 +1,75 @@
|
|
|
+package oss
|
|
|
+
|
|
|
+import (
|
|
|
+ "math"
|
|
|
+ "net/http"
|
|
|
+
|
|
|
+ "fmt"
|
|
|
+
|
|
|
+ . "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)
|
|
|
+ fmt.Printf("completed\n")
|
|
|
+}
|
|
|
+
|
|
|
+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)
|
|
|
+}
|