-
Notifications
You must be signed in to change notification settings - Fork 448
Closed as not planned
Description
Description
Purpose
Avoid declaring non exported upstream interfaces as separate types just so they can be mocked.
Details
https://go.dev/play/p/Bt74sBt01Yl
package main
import "fmt"
// go generate mockery Employee.address
// struct with interface
type Employee struct {
address interface {
StreetName() string
BlockNumber() int
}
}
// constructor with inlined interface
func NewEmployee(
address interface {
StreetName() string
BlockNumber() int
},
) Employee {
return Employee{address: address}
}
// concerete upstream
type HumanAddress struct {
streetName string
blockNumber int
}
func (h HumanAddress) StreetName() string { return h.streetName }
func (h HumanAddress) BlockNumber() int { return h.blockNumber }
func main() {
e := NewEmployee(HumanAddress{streetName: "some-street", blockNumber: 11})
fmt.Printf("%#v", e)
}thaonx
Metadata
Metadata
Assignees
Labels
No labels