Skip to content

interface mocking #3

@ZaynJarvis

Description

@ZaynJarvis

Is your feature request related to a problem? Please describe.

A quick guide for interface mocking is needed

Describe the solution you'd like

type Fooer interface{
	Foo(string) string
}

type A struct{}

func (a A) Foo(in string) string { return in }

func UseFoo(f Fooer) string {
        // something
        return f.Foo("")
}

func TestMockXXX(t *testing.T) {
	PatchConvey("TestMockXXX", t, func() {
                Mock(Fooer.Foo).Return("c").Build() // something like this is needed

		So(UseFoo(A{}), ShouldEqual, "c") // assert `Fooer.Foo` is mocked
	})
}

Describe alternatives you've considered

func TestMockXXX(t *testing.T) {
	PatchConvey("TestMockXXX", t, func() {
                MockInterface(Fooer.Foo).Return("c").Build() // something like this is needed

		So(UseFoo(A{}), ShouldEqual, "c") // assert `Fooer.Foo` is mocked
	})
}

Additional context

  • for now GetNestedMethod seems to work, but not elegant.
  • I know I can do interface insertion, but this Mock func is just so good, I want to use it the same way.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthelp wantedExtra attention is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions