Comments (1)
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)
}
}
from go-mock.
Related Issues (8)
- When using MockFunction.Call, only the first set of return values is returned HOT 1
- Please add Go module HOT 3
- Mock not working HOT 1
- Question [Not a issue] HOT 4
- Support variable number of arguments HOT 6
- how to walk over the limits: need use obj as a param to control if it's a mock obj HOT 6
- Feature Request: Given an interface, generate a mock HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-mock.