[go-nuts] Re: How to mock functions in Go ?

2019-08-01 Thread kyle . butz
You'll want to check out `gomock` and `mockgen`. You'll need to write an interface to be able to mock, so you may need to write a receiver struct to encapsulate os.Hostname() or whatever you need to mock, then mock your HostnameGetter (surely a better name than that), maybe? type OsClient

[go-nuts] Re: How to mock functions in Go ?

2019-08-01 Thread Kyle Butz
You'll want to look into gomock and mockgen. To get started mocking, you'll need an interface, so maybe writing a receiver function encapsulating os.Hostname(), then consuming that with an interface. type OsClient struct {} func (o *OsClient) GetOSHostname() (string, error) { return

Re: [go-nuts] Does client.go#transport() reuse s global DefaultTransport when http.Client's Transport is nil?

2018-10-17 Thread Kyle Butz
-5, Burak Serdar wrote: > > On Wed, Oct 17, 2018 at 10:30 AM Kyle Butz > wrote: > > > > Hi All! > > > > I'm having trouble understanding whether a new http.Client{} with no > Transport set will use a new copy of DefaultTransport, or the global? > &

[go-nuts] Does client.go#transport() reuse s global DefaultTransport when http.Client's Transport is nil?

2018-10-17 Thread Kyle Butz
Hi All! I'm having trouble understanding whether a new http.Client{} with no Transport set will use a new copy of DefaultTransport, or the global? >From client.go: func (c *Client) transport() RoundTripper { if c.Transport != nil { return c.Transport } return DefaultTransport }