Closed kingeasternsun closed 6 years ago
I got it
package main
import (
"fmt"
"github.com/maraino/go-mock"
)
type Infost struct {
A string
}
type Client interface {
// Request(url *url.URL) (int, string, error)
Info(a string) Infost
Query() Infost
}
type MyClient struct {
mock.Mock
}
// func (c *MyClient) Request(url *url.URL) (int, string, error) {
// ret := c.Called(url)
// return ret.Int(0), ret.String(1), ret.Error(2)
// }
func (c *MyClient) Info(a string) Infost {
ret := c.Called(a)
return ret.Get(0).(Infost)
}
func (c *MyClient) Query() Infost {
ret := c.Called()
return ret.Get(0).(Infost)
}
func main() {
c := &MyClient{}
// url, _ := url.Parse("http://www.example.org")
// c.When("Request", url).Return(200, "{result:1}", nil)
// // c.When("Request", url).Return(200, "{result:2}", nil)
// c.When("Request", mock.Any).Return(500, "{result:0}", fmt.Errorf("Internal Server Error")).Times(1)
// code, json, err := c.Request(url)
// fmt.Printf("Code: %d, JSON: %s, Error: %v\n", code, json, err)
// url, _ = url.Parse("http://www.github.com")
// code, json, err = c.Request(url)
// fmt.Printf("Code: %d, JSON: %s, Error: %v\n", code, json, err)
c.When("Info", "a").Return(Infost{"love"})
c.When("Query").Return(Infost{"lovequery"})
info := c.Info("a")
fmt.Println(info)
queryInfo := c.Query()
fmt.Println(queryInfo)
if ok, err := c.Verify(); !ok {
fmt.Println(err)
}
}
panic