nelsam/hel

Support Types Implementing Interface Types

Opened this issue · 0 comments

We usually don't want to generate mocks for interface types in other packages, to help reduce the urge to use massive interface types as the source of truth for what a type can do. However, there's an exception to this:

// foo/foo.go

type Baz interface{
    //...
}

type Bar interface {
    Bar(Baz)
}

type Foo struct {
    //...
}

func NewFoo(bar Bar) Foo {
    //...
}

// bar/bar.go

type Bar struct {}

func (b *Bar) Bar(foo.Baz)

In this case, Bar has a method that must accept an interface type from another package. Testing this code with hel becomes extremely difficult.

For cases like this, we should provide some way to relate the concrete type back to the interface type that is being implemented. It's easy enough to construct an interface type from the implemented methods, but searching all packages for interface types that are a subset of those methods may not be feasible. We may have to handle some syntax in the local code to deal with that.

As a worst case, we could handle something like this:

// Window is a type to handle windows.
//
// implements: (git.sr.ht/~nelsam/grpc).Window
type Window struct{}