2016-04-06 18:33:57 +01:00
|
|
|
package mock
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/micro/go-micro/errors"
|
|
|
|
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestClient(t *testing.T) {
|
2016-04-06 18:38:33 +01:00
|
|
|
type TestResponse struct {
|
2016-04-06 18:37:46 +01:00
|
|
|
Param string
|
|
|
|
}
|
|
|
|
|
2016-04-06 18:33:57 +01:00
|
|
|
response := []MockResponse{
|
|
|
|
{Method: "Foo.Bar", Response: map[string]interface{}{"foo": "bar"}},
|
2016-04-06 18:38:33 +01:00
|
|
|
{Method: "Foo.Struct", Response: &TestResponse{Param: "aparam"}},
|
2016-04-06 18:33:57 +01:00
|
|
|
{Method: "Foo.Fail", Error: errors.InternalServerError("go.mock", "failed")},
|
|
|
|
}
|
|
|
|
|
|
|
|
c := NewClient(Response("go.mock", response))
|
|
|
|
|
|
|
|
for _, r := range response {
|
|
|
|
req := c.NewJsonRequest("go.mock", r.Method, map[string]interface{}{"foo": "bar"})
|
2016-04-06 18:37:46 +01:00
|
|
|
var rsp interface{}
|
2016-04-06 18:33:57 +01:00
|
|
|
|
|
|
|
err := c.Call(context.TODO(), req, &rsp)
|
|
|
|
|
|
|
|
if err != r.Error {
|
|
|
|
t.Fatalf("Expecter error %v got %v", r.Error, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Log(rsp)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|