Probe revamped to provide for a new WrappedError struct to wrap probes as error interface

This convenience was necessary to be used for golang library functions like io.Copy and io.Pipe
where we shouldn't be writing proxies and alternatives returning *probe.Error

This change also brings more changes across code base for clear separation regarding where an error
interface should be passed encapsulating *probe.Error and where it should be used as is.
This commit is contained in:
Harshavardhana
2015-08-07 23:47:22 -07:00
parent 28d9565400
commit 45b59b8456
34 changed files with 392 additions and 363 deletions

View File

@@ -13,33 +13,41 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package probe
package probe_test
import (
"os"
"testing"
"github.com/minio/minio/pkg/probe"
. "gopkg.in/check.v1"
)
func testDummy() *Error {
_, e := os.Stat("this-file-cannot-exit-234234232423423")
es := New(e)
es.Trace("this is hell", "asdf")
func Test(t *testing.T) { TestingT(t) }
type MySuite struct{}
var _ = Suite(&MySuite{})
func testDummy() *probe.Error {
_, e := os.Stat("this-file-cannot-exit")
es := probe.NewError(e)
es.Trace("Important info 1", "Import into 2")
return es
}
func TestProbe(t *testing.T) {
func (s *MySuite) TestProbe(c *C) {
es := testDummy()
if es == nil {
t.Fail()
}
c.Assert(es, Not(Equals), nil)
newES := es.Trace()
if newES == nil {
t.Fail()
}
/*
fmt.Println(es)
fmt.Println(es.JSON())
fmt.Println(es.ToError())
*/
c.Assert(newES, Not(Equals), nil)
}
func (s *MySuite) TestWrappedError(c *C) {
_, e := os.Stat("this-file-cannot-exit")
es := probe.NewError(e) // *probe.Error
e = probe.NewWrappedError(es) // *probe.WrappedError
_, ok := probe.ToWrappedError(e)
c.Assert(ok, Equals, true)
}