Commit c5e75f91 authored by Brian Tiger Chow's avatar Brian Tiger Chow Committed by Juan Batiz-Benet

tests(2/main) errClient

Discovered this quirk about interfaces.

@whyrusleeping
@mappum
@jbenet

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parent 0a93f9d7
......@@ -263,12 +263,18 @@ func callCommand(req cmds.Request, root *cmds.Command) (cmds.Response, error) {
}
func isClientError(err error) bool {
// Somewhat suprisingly, the pointer cast fails to recognize commands.Error
// passed as values, so we check both.
// cast to cmds.Error
cmdErr, ok := err.(*cmds.Error)
if !ok {
return false
switch e := err.(type) {
case *cmds.Error:
return e.Code == cmds.ErrClient
case cmds.Error:
return e.Code == cmds.ErrClient
}
return cmdErr.Code == cmds.ErrClient
return false
}
func getConfigRoot(req cmds.Request) (string, error) {
......
package main
import (
"testing"
"github.com/jbenet/go-ipfs/commands"
)
func TestIsCientErr(t *testing.T) {
t.Log("Catch both pointers and values")
if !isClientError(commands.Error{Code: commands.ErrClient}) {
t.Errorf("misidentified value")
}
if !isClientError(&commands.Error{Code: commands.ErrClient}) {
t.Errorf("misidentified pointer")
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment