Commit c758a4cf authored by Jeromy's avatar Jeromy

Fix MakeTypedEncoder bug

parent c680937a
1.0.5: QmZ9hww8R3FKrDRCYPxhN13m6XgjPDpaSvdUfisPvERzXz
1.0.6: QmWGgKRz5S24SqaAapF5PPCfYfLT7MexJZewN5M82CQTzs
......@@ -103,7 +103,11 @@ func MakeTypedEncoder(f interface{}) func(*Request) func(io.Writer) Encoder {
reflect.ValueOf(i),
})
return out[0].Interface().(error)
err, ok := out[0].Interface().(error)
if ok {
return err
}
return nil
})
}
......
package cmds
import (
"bytes"
"fmt"
"io"
"testing"
)
type fooTestObj struct {
Good bool
}
func TestMakeTypedEncoder(t *testing.T) {
expErr := fmt.Errorf("command fooTestObj failed")
f := MakeTypedEncoder(func(req *Request, w io.Writer, v *fooTestObj) error {
if v.Good {
return nil
}
return expErr
})
req := &Request{}
encoderFunc := f(req)
buf := new(bytes.Buffer)
encoder := encoderFunc(buf)
if err := encoder.Encode(&fooTestObj{true}); err != nil {
t.Fatal(err)
}
if err := encoder.Encode(&fooTestObj{false}); err != expErr {
t.Fatal("expected: ", expErr)
}
}
......@@ -47,6 +47,6 @@
"license": "MIT",
"name": "go-ipfs-cmds",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "1.0.5"
"version": "1.0.6"
}
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