Adding tests for cmd-common isValidRetry
This commit is contained in:
@@ -34,6 +34,7 @@ import (
|
||||
|
||||
// isValidRetry - check if we should retry for the given error sequence
|
||||
func isValidRetry(err error) bool {
|
||||
err = iodine.New(err, nil)
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
+47
-3
@@ -21,14 +21,29 @@ import (
|
||||
|
||||
"github.com/cheggaaa/pb"
|
||||
|
||||
"errors"
|
||||
. "github.com/minio-io/check"
|
||||
"github.com/minio-io/minio/pkg/iodine"
|
||||
"net"
|
||||
)
|
||||
|
||||
type StatusBarSuite struct{}
|
||||
type CommonSuite struct{}
|
||||
|
||||
var _ = Suite(&StatusBarSuite{})
|
||||
type testAddr struct{}
|
||||
|
||||
func (s *StatusBarSuite) TestStatusBar(c *C) {
|
||||
func (ta *testAddr) Network() string {
|
||||
return ta.String()
|
||||
}
|
||||
func (ta *testAddr) Error() string {
|
||||
return ta.String()
|
||||
}
|
||||
func (ta *testAddr) String() string {
|
||||
return "testAddr"
|
||||
}
|
||||
|
||||
var _ = Suite(&CommonSuite{})
|
||||
|
||||
func (s *CommonSuite) TestStatusBar(c *C) {
|
||||
bar := startBar(1024)
|
||||
c.Assert(bar, Not(IsNil))
|
||||
c.Assert(bar.Units, Equals, pb.U_BYTES)
|
||||
@@ -36,3 +51,32 @@ func (s *StatusBarSuite) TestStatusBar(c *C) {
|
||||
c.Assert(bar.NotPrint, Equals, true)
|
||||
c.Assert(bar.ShowSpeed, Equals, true)
|
||||
}
|
||||
|
||||
func (s *CommonSuite) TestIsValidRetry(c *C) {
|
||||
opError := &net.OpError{
|
||||
Op: "read",
|
||||
Net: "net",
|
||||
Addr: &testAddr{},
|
||||
Err: errors.New("Op Error"),
|
||||
}
|
||||
c.Assert(isValidRetry(nil), Equals, false)
|
||||
c.Assert(isValidRetry(errors.New("hello")), Equals, false)
|
||||
c.Assert(isValidRetry(iodine.New(errors.New("hello"), nil)), Equals, false)
|
||||
c.Assert(isValidRetry(&net.DNSError{}), Equals, true)
|
||||
c.Assert(isValidRetry(iodine.New(&net.DNSError{}, nil)), Equals, true)
|
||||
// op error read
|
||||
c.Assert(isValidRetry(opError), Equals, true)
|
||||
c.Assert(isValidRetry(iodine.New(opError, nil)), Equals, true)
|
||||
// op error write
|
||||
opError.Op = "write"
|
||||
c.Assert(isValidRetry(opError), Equals, true)
|
||||
c.Assert(isValidRetry(iodine.New(opError, nil)), Equals, true)
|
||||
// op error dial
|
||||
opError.Op = "dial"
|
||||
c.Assert(isValidRetry(opError), Equals, true)
|
||||
c.Assert(isValidRetry(iodine.New(opError, nil)), Equals, true)
|
||||
// op error foo
|
||||
opError.Op = "foo"
|
||||
c.Assert(isValidRetry(opError), Equals, false)
|
||||
c.Assert(isValidRetry(iodine.New(opError, nil)), Equals, false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user