How to use EXPECT method of empty_interface Package

Best Mock code snippet using empty_interface.EXPECT

generator_test.go

Source:generator_test.go Github

copy

Full Screen

1package mockery2import (3 "bufio"4 "fmt"5 "go/format"6 "io/ioutil"7 "path/filepath"8 "strings"9 "testing"10 "github.com/stretchr/testify/require"11 "github.com/stretchr/testify/suite"12)13const pkg = "test"14type GeneratorSuite struct {15 suite.Suite16 parser *Parser17}18func (s *GeneratorSuite) SetupTest() {19 s.parser = NewParser(nil)20}21func (s *GeneratorSuite) getInterfaceFromFile(interfacePath, interfaceName string) *Interface {22 if !strings.Contains(interfacePath, fixturePath) {23 interfacePath = filepath.Join(fixturePath, interfacePath)24 }25 s.NoError(26 s.parser.Parse(interfacePath), "The parser is able to parse the given file.",27 )28 s.NoError(29 s.parser.Load(), "The parser is able to load the config.",30 )31 iface, err := s.parser.Find(interfaceName)32 s.Require().NoError(err)33 s.Require().NotNil(iface)34 return iface35}36func (s *GeneratorSuite) getGenerator(37 filepath, interfaceName string, inPackage bool,38) *Generator {39 return NewGenerator(s.getInterfaceFromFile(filepath, interfaceName), pkg, inPackage)40}41func (s *GeneratorSuite) checkGeneration(42 filepath, interfaceName string, inPackage bool, expected string,43) *Generator {44 generator := s.getGenerator(filepath, interfaceName, inPackage)45 s.NoError(generator.Generate(), "The generator ran without errors.")46 // Mirror the formatting done by normally done by golang.org/x/tools/imports in Generator.Write.47 //48 // While we could possibly reuse Generator.Write here in addition to Generator.Generate,49 // it would require changing Write's signature to accept custom options, specifically to50 // allow the fragments in preexisting cases. It's assumed that this approximation,51 // just formatting the source, is sufficient for the needs of the current test styles.52 var actual []byte53 actual, fmtErr := format.Source(generator.buf.Bytes())54 s.NoError(fmtErr, "The formatter ran without errors.")55 // Compare lines for easier debugging via testify's slice diff output56 expectedLines := strings.Split(expected, "\n")57 actualLines := strings.Split(string(actual), "\n")58 s.Equal(59 expectedLines, actualLines,60 "The generator produced the expected output.",61 )62 return generator63}64func (s *GeneratorSuite) checkPrologueGeneration(65 generator *Generator, expected string,66) {67 generator.GeneratePrologue("mocks")68 s.Equal(69 expected, generator.buf.String(),70 "The generator produced the expected prologue.",71 )72}73func (s *GeneratorSuite) TestCalculateImport() {74 gp := []string{"a/src", "b/src"}75 s.Equal("c", calculateImport(gp, "a/src/c"))76 s.Equal("c", calculateImport(gp, "b/src/c"))77 s.Equal("d/src/c", calculateImport(gp, "d/src/c"))78}79func (s *GeneratorSuite) TestGenerator() {80 expected := `// Requester is an autogenerated mock type for the Requester type81type Requester struct {82 mock.Mock83}84type RequesterExpectation struct {85 mock *mock.Mock86}87func (_m *Requester) Expect() *RequesterExpectation {88 return &RequesterExpectation{mock: &_m.Mock}89}90// Get provides a mock function with given fields: path91func (_m *Requester) Get(path string) (string, error) {92 ret := _m.Called(path)93 var r0 string94 if rf, ok := ret.Get(0).(func(string) string); ok {95 r0 = rf(path)96 } else {97 r0 = ret.Get(0).(string)98 }99 var r1 error100 if rf, ok := ret.Get(1).(func(string) error); ok {101 r1 = rf(path)102 } else {103 r1 = ret.Error(1)104 }105 return r0, r1106}107type RequesterGetExpectation struct {108 call *mock.Call109}110func (_e *RequesterExpectation) Get(path string) *RequesterGetExpectation {111 return &RequesterGetExpectation{112 call: _e.mock.On("Get", path),113 }114}115func (_e *RequesterGetExpectation) ToReturn(_a0 string, _a1 error) *mock.Call {116 return _e.call.Return(_a0, _a1)117}118`119 s.checkGeneration(testFile, "Requester", false, expected)120}121func (s *GeneratorSuite) TestGeneratorSingleReturn() {122 expected := `// Requester2 is an autogenerated mock type for the Requester2 type123type Requester2 struct {124 mock.Mock125}126type Requester2Expectation struct {127 mock *mock.Mock128}129func (_m *Requester2) Expect() *Requester2Expectation {130 return &Requester2Expectation{mock: &_m.Mock}131}132// Get provides a mock function with given fields: path133func (_m *Requester2) Get(path string) error {134 ret := _m.Called(path)135 var r0 error136 if rf, ok := ret.Get(0).(func(string) error); ok {137 r0 = rf(path)138 } else {139 r0 = ret.Error(0)140 }141 return r0142}143type Requester2GetExpectation struct {144 call *mock.Call145}146func (_e *Requester2Expectation) Get(path string) *Requester2GetExpectation {147 return &Requester2GetExpectation{148 call: _e.mock.On("Get", path),149 }150}151func (_e *Requester2GetExpectation) ToReturn(_a0 error) *mock.Call {152 return _e.call.Return(_a0)153}154`155 s.checkGeneration(testFile2, "Requester2", false, expected)156}157func (s *GeneratorSuite) TestGeneratorNoArguments() {158 expected := `// Requester3 is an autogenerated mock type for the Requester3 type159type Requester3 struct {160 mock.Mock161}162type Requester3Expectation struct {163 mock *mock.Mock164}165func (_m *Requester3) Expect() *Requester3Expectation {166 return &Requester3Expectation{mock: &_m.Mock}167}168// Get provides a mock function with given fields:169func (_m *Requester3) Get() error {170 ret := _m.Called()171 var r0 error172 if rf, ok := ret.Get(0).(func() error); ok {173 r0 = rf()174 } else {175 r0 = ret.Error(0)176 }177 return r0178}179type Requester3GetExpectation struct {180 call *mock.Call181}182func (_e *Requester3Expectation) Get() *Requester3GetExpectation {183 return &Requester3GetExpectation{184 call: _e.mock.On("Get"),185 }186}187func (_e *Requester3GetExpectation) ToReturn(_a0 error) *mock.Call {188 return _e.call.Return(_a0)189}190`191 s.checkGeneration(192 filepath.Join(fixturePath, "requester3.go"), "Requester3", false,193 expected,194 )195}196func (s *GeneratorSuite) TestGeneratorNoNothing() {197 expected := `// Requester4 is an autogenerated mock type for the Requester4 type198type Requester4 struct {199 mock.Mock200}201type Requester4Expectation struct {202 mock *mock.Mock203}204func (_m *Requester4) Expect() *Requester4Expectation {205 return &Requester4Expectation{mock: &_m.Mock}206}207// Get provides a mock function with given fields:208func (_m *Requester4) Get() {209 _m.Called()210}211type Requester4GetExpectation struct {212 call *mock.Call213}214func (_e *Requester4Expectation) Get() *Requester4GetExpectation {215 return &Requester4GetExpectation{216 call: _e.mock.On("Get"),217 }218}219func (_e *Requester4GetExpectation) ToReturn() *mock.Call {220 return _e.call.Return()221}222`223 s.checkGeneration(224 filepath.Join(fixturePath, "requester4.go"), "Requester4", false,225 expected,226 )227}228func (s *GeneratorSuite) TestGeneratorUnexported() {229 expected := `// mockRequester_unexported is an autogenerated mock type for the requester_unexported type230type mockRequester_unexported struct {231 mock.Mock232}233type mockRequester_unexportedExpectation struct {234 mock *mock.Mock235}236func (_m *mockRequester_unexported) Expect() *mockRequester_unexportedExpectation {237 return &mockRequester_unexportedExpectation{mock: &_m.Mock}238}239// Get provides a mock function with given fields:240func (_m *mockRequester_unexported) Get() {241 _m.Called()242}243type mockRequester_unexportedGetExpectation struct {244 call *mock.Call245}246func (_e *mockRequester_unexportedExpectation) Get() *mockRequester_unexportedGetExpectation {247 return &mockRequester_unexportedGetExpectation{248 call: _e.mock.On("Get"),249 }250}251func (_e *mockRequester_unexportedGetExpectation) ToReturn() *mock.Call {252 return _e.call.Return()253}254`255 s.checkGeneration(256 "requester_unexported.go", "requester_unexported", true, expected,257 )258}259func (s *GeneratorSuite) TestGeneratorPrologue() {260 generator := s.getGenerator(testFile, "Requester", false)261 expected := `package mocks262import mock "github.com/stretchr/testify/mock"263import test "github.com/namely/mockery/mockery/fixtures"264`265 s.checkPrologueGeneration(generator, expected)266}267func (s *GeneratorSuite) TestGeneratorPrologueWithImports() {268 generator := s.getGenerator("requester_ns.go", "RequesterNS", false)269 expected := `package mocks270import http "net/http"271import mock "github.com/stretchr/testify/mock"272import test "github.com/namely/mockery/mockery/fixtures"273`274 s.checkPrologueGeneration(generator, expected)275}276func (s *GeneratorSuite) TestGeneratorPrologueWithMultipleImportsSameName() {277 generator := s.getGenerator("same_name_imports.go", "Example", false)278 expected := `package mocks279import fixtureshttp "github.com/namely/mockery/mockery/fixtures/http"280import http "net/http"281import mock "github.com/stretchr/testify/mock"282import test "github.com/namely/mockery/mockery/fixtures"283`284 s.checkPrologueGeneration(generator, expected)285}286func (s *GeneratorSuite) TestGeneratorPrologueNote() {287 generator := s.getGenerator(testFile, "Requester", false)288 generator.GeneratePrologueNote("A\\nB")289 expected := fmt.Sprintf(`// Code generated by mockery v%s. DO NOT EDIT.290// A291// B292`, SemVer)293 s.Equal(expected, generator.buf.String())294}295func (s *GeneratorSuite) TestVersionOnCorrectLine() {296 gen := s.getGenerator(testFile, "Requester", false)297 // Run everything that is ran by the GeneratorVisitor298 gen.GeneratePrologueNote("A\\nB")299 gen.GeneratePrologue(pkg)300 err := gen.Generate()301 require.NoError(s.T(), err)302 scan := bufio.NewScanner(&gen.buf)303 s.Contains("Code generated by", scan.Text())304}305func (s *GeneratorSuite) TestGeneratorChecksInterfacesForNilable() {306 expected := `// RequesterIface is an autogenerated mock type for the RequesterIface type307type RequesterIface struct {308 mock.Mock309}310type RequesterIfaceExpectation struct {311 mock *mock.Mock312}313func (_m *RequesterIface) Expect() *RequesterIfaceExpectation {314 return &RequesterIfaceExpectation{mock: &_m.Mock}315}316// Get provides a mock function with given fields:317func (_m *RequesterIface) Get() io.Reader {318 ret := _m.Called()319 var r0 io.Reader320 if rf, ok := ret.Get(0).(func() io.Reader); ok {321 r0 = rf()322 } else {323 if ret.Get(0) != nil {324 r0 = ret.Get(0).(io.Reader)325 }326 }327 return r0328}329type RequesterIfaceGetExpectation struct {330 call *mock.Call331}332func (_e *RequesterIfaceExpectation) Get() *RequesterIfaceGetExpectation {333 return &RequesterIfaceGetExpectation{334 call: _e.mock.On("Get"),335 }336}337func (_e *RequesterIfaceGetExpectation) ToReturn(_a0 io.Reader) *mock.Call {338 return _e.call.Return(_a0)339}340`341 s.checkGeneration(342 filepath.Join(fixturePath, "requester_iface.go"), "RequesterIface",343 false, expected,344 )345}346func (s *GeneratorSuite) TestGeneratorPointers() {347 expected := `// RequesterPtr is an autogenerated mock type for the RequesterPtr type348type RequesterPtr struct {349 mock.Mock350}351type RequesterPtrExpectation struct {352 mock *mock.Mock353}354func (_m *RequesterPtr) Expect() *RequesterPtrExpectation {355 return &RequesterPtrExpectation{mock: &_m.Mock}356}357// Get provides a mock function with given fields: path358func (_m *RequesterPtr) Get(path string) (*string, error) {359 ret := _m.Called(path)360 var r0 *string361 if rf, ok := ret.Get(0).(func(string) *string); ok {362 r0 = rf(path)363 } else {364 if ret.Get(0) != nil {365 r0 = ret.Get(0).(*string)366 }367 }368 var r1 error369 if rf, ok := ret.Get(1).(func(string) error); ok {370 r1 = rf(path)371 } else {372 r1 = ret.Error(1)373 }374 return r0, r1375}376type RequesterPtrGetExpectation struct {377 call *mock.Call378}379func (_e *RequesterPtrExpectation) Get(path string) *RequesterPtrGetExpectation {380 return &RequesterPtrGetExpectation{381 call: _e.mock.On("Get", path),382 }383}384func (_e *RequesterPtrGetExpectation) ToReturn(_a0 *string, _a1 error) *mock.Call {385 return _e.call.Return(_a0, _a1)386}387`388 s.checkGeneration(389 filepath.Join(fixturePath, "requester_ptr.go"), "RequesterPtr", false,390 expected,391 )392}393func (s *GeneratorSuite) TestGeneratorSlice() {394 expected := `// RequesterSlice is an autogenerated mock type for the RequesterSlice type395type RequesterSlice struct {396 mock.Mock397}398type RequesterSliceExpectation struct {399 mock *mock.Mock400}401func (_m *RequesterSlice) Expect() *RequesterSliceExpectation {402 return &RequesterSliceExpectation{mock: &_m.Mock}403}404// Get provides a mock function with given fields: path405func (_m *RequesterSlice) Get(path string) ([]string, error) {406 ret := _m.Called(path)407 var r0 []string408 if rf, ok := ret.Get(0).(func(string) []string); ok {409 r0 = rf(path)410 } else {411 if ret.Get(0) != nil {412 r0 = ret.Get(0).([]string)413 }414 }415 var r1 error416 if rf, ok := ret.Get(1).(func(string) error); ok {417 r1 = rf(path)418 } else {419 r1 = ret.Error(1)420 }421 return r0, r1422}423type RequesterSliceGetExpectation struct {424 call *mock.Call425}426func (_e *RequesterSliceExpectation) Get(path string) *RequesterSliceGetExpectation {427 return &RequesterSliceGetExpectation{428 call: _e.mock.On("Get", path),429 }430}431func (_e *RequesterSliceGetExpectation) ToReturn(_a0 []string, _a1 error) *mock.Call {432 return _e.call.Return(_a0, _a1)433}434`435 s.checkGeneration(436 filepath.Join(fixturePath, "requester_slice.go"), "RequesterSlice",437 false, expected,438 )439}440func (s *GeneratorSuite) TestGeneratorArrayLiteralLen() {441 expected := `// RequesterArray is an autogenerated mock type for the RequesterArray type442type RequesterArray struct {443 mock.Mock444}445type RequesterArrayExpectation struct {446 mock *mock.Mock447}448func (_m *RequesterArray) Expect() *RequesterArrayExpectation {449 return &RequesterArrayExpectation{mock: &_m.Mock}450}451// Get provides a mock function with given fields: path452func (_m *RequesterArray) Get(path string) ([2]string, error) {453 ret := _m.Called(path)454 var r0 [2]string455 if rf, ok := ret.Get(0).(func(string) [2]string); ok {456 r0 = rf(path)457 } else {458 if ret.Get(0) != nil {459 r0 = ret.Get(0).([2]string)460 }461 }462 var r1 error463 if rf, ok := ret.Get(1).(func(string) error); ok {464 r1 = rf(path)465 } else {466 r1 = ret.Error(1)467 }468 return r0, r1469}470type RequesterArrayGetExpectation struct {471 call *mock.Call472}473func (_e *RequesterArrayExpectation) Get(path string) *RequesterArrayGetExpectation {474 return &RequesterArrayGetExpectation{475 call: _e.mock.On("Get", path),476 }477}478func (_e *RequesterArrayGetExpectation) ToReturn(_a0 [2]string, _a1 error) *mock.Call {479 return _e.call.Return(_a0, _a1)480}481`482 s.checkGeneration(483 filepath.Join(fixturePath, "requester_array.go"), "RequesterArray",484 false, expected,485 )486}487func (s *GeneratorSuite) TestGeneratorNamespacedTypes() {488 expected := `// RequesterNS is an autogenerated mock type for the RequesterNS type489type RequesterNS struct {490 mock.Mock491}492type RequesterNSExpectation struct {493 mock *mock.Mock494}495func (_m *RequesterNS) Expect() *RequesterNSExpectation {496 return &RequesterNSExpectation{mock: &_m.Mock}497}498// Get provides a mock function with given fields: path499func (_m *RequesterNS) Get(path string) (http.Response, error) {500 ret := _m.Called(path)501 var r0 http.Response502 if rf, ok := ret.Get(0).(func(string) http.Response); ok {503 r0 = rf(path)504 } else {505 r0 = ret.Get(0).(http.Response)506 }507 var r1 error508 if rf, ok := ret.Get(1).(func(string) error); ok {509 r1 = rf(path)510 } else {511 r1 = ret.Error(1)512 }513 return r0, r1514}515type RequesterNSGetExpectation struct {516 call *mock.Call517}518func (_e *RequesterNSExpectation) Get(path string) *RequesterNSGetExpectation {519 return &RequesterNSGetExpectation{520 call: _e.mock.On("Get", path),521 }522}523func (_e *RequesterNSGetExpectation) ToReturn(_a0 http.Response, _a1 error) *mock.Call {524 return _e.call.Return(_a0, _a1)525}526`527 s.checkGeneration(528 filepath.Join(fixturePath, "requester_ns.go"), "RequesterNS", false,529 expected,530 )531}532func (s *GeneratorSuite) TestGeneratorWhereArgumentNameConflictsWithImport() {533 expected := `// RequesterArgSameAsImport is an autogenerated mock type for the RequesterArgSameAsImport type534type RequesterArgSameAsImport struct {535 mock.Mock536}537type RequesterArgSameAsImportExpectation struct {538 mock *mock.Mock539}540func (_m *RequesterArgSameAsImport) Expect() *RequesterArgSameAsImportExpectation {541 return &RequesterArgSameAsImportExpectation{mock: &_m.Mock}542}543// Get provides a mock function with given fields: _a0544func (_m *RequesterArgSameAsImport) Get(_a0 string) *json.RawMessage {545 ret := _m.Called(_a0)546 var r0 *json.RawMessage547 if rf, ok := ret.Get(0).(func(string) *json.RawMessage); ok {548 r0 = rf(_a0)549 } else {550 if ret.Get(0) != nil {551 r0 = ret.Get(0).(*json.RawMessage)552 }553 }554 return r0555}556type RequesterArgSameAsImportGetExpectation struct {557 call *mock.Call558}559func (_e *RequesterArgSameAsImportExpectation) Get(_a0 string) *RequesterArgSameAsImportGetExpectation {560 return &RequesterArgSameAsImportGetExpectation{561 call: _e.mock.On("Get", _a0),562 }563}564func (_e *RequesterArgSameAsImportGetExpectation) ToReturn(_a0 *json.RawMessage) *mock.Call {565 return _e.call.Return(_a0)566}567`568 s.checkGeneration(569 filepath.Join(fixturePath, "requester_arg_same_as_import.go"),570 "RequesterArgSameAsImport", false, expected,571 )572}573func (s *GeneratorSuite) TestGeneratorWhereArgumentNameConflictsWithNamedImport() {574 expected := `// RequesterArgSameAsNamedImport is an autogenerated mock type for the RequesterArgSameAsNamedImport type575type RequesterArgSameAsNamedImport struct {576 mock.Mock577}578type RequesterArgSameAsNamedImportExpectation struct {579 mock *mock.Mock580}581func (_m *RequesterArgSameAsNamedImport) Expect() *RequesterArgSameAsNamedImportExpectation {582 return &RequesterArgSameAsNamedImportExpectation{mock: &_m.Mock}583}584// Get provides a mock function with given fields: _a0585func (_m *RequesterArgSameAsNamedImport) Get(_a0 string) *json.RawMessage {586 ret := _m.Called(_a0)587 var r0 *json.RawMessage588 if rf, ok := ret.Get(0).(func(string) *json.RawMessage); ok {589 r0 = rf(_a0)590 } else {591 if ret.Get(0) != nil {592 r0 = ret.Get(0).(*json.RawMessage)593 }594 }595 return r0596}597type RequesterArgSameAsNamedImportGetExpectation struct {598 call *mock.Call599}600func (_e *RequesterArgSameAsNamedImportExpectation) Get(_a0 string) *RequesterArgSameAsNamedImportGetExpectation {601 return &RequesterArgSameAsNamedImportGetExpectation{602 call: _e.mock.On("Get", _a0),603 }604}605func (_e *RequesterArgSameAsNamedImportGetExpectation) ToReturn(_a0 *json.RawMessage) *mock.Call {606 return _e.call.Return(_a0)607}608`609 s.checkGeneration(610 filepath.Join(fixturePath, "requester_arg_same_as_named_import.go"),611 "RequesterArgSameAsNamedImport", false, expected,612 )613}614func (s *GeneratorSuite) TestGeneratorWhereArgumentNameConflictsWithPackage() {615 expected := `// RequesterArgSameAsPkg is an autogenerated mock type for the RequesterArgSameAsPkg type616type RequesterArgSameAsPkg struct {617 mock.Mock618}619type RequesterArgSameAsPkgExpectation struct {620 mock *mock.Mock621}622func (_m *RequesterArgSameAsPkg) Expect() *RequesterArgSameAsPkgExpectation {623 return &RequesterArgSameAsPkgExpectation{mock: &_m.Mock}624}625// Get provides a mock function with given fields: _a0626func (_m *RequesterArgSameAsPkg) Get(_a0 string) {627 _m.Called(_a0)628}629type RequesterArgSameAsPkgGetExpectation struct {630 call *mock.Call631}632func (_e *RequesterArgSameAsPkgExpectation) Get(_a0 string) *RequesterArgSameAsPkgGetExpectation {633 return &RequesterArgSameAsPkgGetExpectation{634 call: _e.mock.On("Get", _a0),635 }636}637func (_e *RequesterArgSameAsPkgGetExpectation) ToReturn() *mock.Call {638 return _e.call.Return()639}640`641 s.checkGeneration(642 filepath.Join(fixturePath, "requester_arg_same_as_pkg.go"),643 "RequesterArgSameAsPkg", false, expected,644 )645}646func (s *GeneratorSuite) TestGeneratorHavingNoNamesOnArguments() {647 expected := `// KeyManager is an autogenerated mock type for the KeyManager type648type KeyManager struct {649 mock.Mock650}651type KeyManagerExpectation struct {652 mock *mock.Mock653}654func (_m *KeyManager) Expect() *KeyManagerExpectation {655 return &KeyManagerExpectation{mock: &_m.Mock}656}657// GetKey provides a mock function with given fields: _a0, _a1658func (_m *KeyManager) GetKey(_a0 string, _a1 uint16) ([]byte, *test.Err) {659 ret := _m.Called(_a0, _a1)660 var r0 []byte661 if rf, ok := ret.Get(0).(func(string, uint16) []byte); ok {662 r0 = rf(_a0, _a1)663 } else {664 if ret.Get(0) != nil {665 r0 = ret.Get(0).([]byte)666 }667 }668 var r1 *test.Err669 if rf, ok := ret.Get(1).(func(string, uint16) *test.Err); ok {670 r1 = rf(_a0, _a1)671 } else {672 if ret.Get(1) != nil {673 r1 = ret.Get(1).(*test.Err)674 }675 }676 return r0, r1677}678type KeyManagerGetKeyExpectation struct {679 call *mock.Call680}681func (_e *KeyManagerExpectation) GetKey(_a0 string, _a1 uint16) *KeyManagerGetKeyExpectation {682 return &KeyManagerGetKeyExpectation{683 call: _e.mock.On("GetKey", _a0, _a1),684 }685}686func (_e *KeyManagerGetKeyExpectation) ToReturn(_a0 []byte, _a1 *test.Err) *mock.Call {687 return _e.call.Return(_a0, _a1)688}689`690 s.checkGeneration(691 filepath.Join(fixturePath, "custom_error.go"), "KeyManager", false,692 expected,693 )694}695func (s *GeneratorSuite) TestGeneratorElidedType() {696 expected := `// RequesterElided is an autogenerated mock type for the RequesterElided type697type RequesterElided struct {698 mock.Mock699}700type RequesterElidedExpectation struct {701 mock *mock.Mock702}703func (_m *RequesterElided) Expect() *RequesterElidedExpectation {704 return &RequesterElidedExpectation{mock: &_m.Mock}705}706// Get provides a mock function with given fields: path, url707func (_m *RequesterElided) Get(path string, url string) error {708 ret := _m.Called(path, url)709 var r0 error710 if rf, ok := ret.Get(0).(func(string, string) error); ok {711 r0 = rf(path, url)712 } else {713 r0 = ret.Error(0)714 }715 return r0716}717type RequesterElidedGetExpectation struct {718 call *mock.Call719}720func (_e *RequesterElidedExpectation) Get(path string, url string) *RequesterElidedGetExpectation {721 return &RequesterElidedGetExpectation{722 call: _e.mock.On("Get", path, url),723 }724}725func (_e *RequesterElidedGetExpectation) ToReturn(_a0 error) *mock.Call {726 return _e.call.Return(_a0)727}728`729 s.checkGeneration(730 filepath.Join(fixturePath, "requester_elided.go"), "RequesterElided",731 false, expected,732 )733}734func (s *GeneratorSuite) TestGeneratorReturnElidedType() {735 expected := `// RequesterReturnElided is an autogenerated mock type for the RequesterReturnElided type736type RequesterReturnElided struct {737 mock.Mock738}739type RequesterReturnElidedExpectation struct {740 mock *mock.Mock741}742func (_m *RequesterReturnElided) Expect() *RequesterReturnElidedExpectation {743 return &RequesterReturnElidedExpectation{mock: &_m.Mock}744}745// Get provides a mock function with given fields: path746func (_m *RequesterReturnElided) Get(path string) (int, int, int, error) {747 ret := _m.Called(path)748 var r0 int749 if rf, ok := ret.Get(0).(func(string) int); ok {750 r0 = rf(path)751 } else {752 r0 = ret.Get(0).(int)753 }754 var r1 int755 if rf, ok := ret.Get(1).(func(string) int); ok {756 r1 = rf(path)757 } else {758 r1 = ret.Get(1).(int)759 }760 var r2 int761 if rf, ok := ret.Get(2).(func(string) int); ok {762 r2 = rf(path)763 } else {764 r2 = ret.Get(2).(int)765 }766 var r3 error767 if rf, ok := ret.Get(3).(func(string) error); ok {768 r3 = rf(path)769 } else {770 r3 = ret.Error(3)771 }772 return r0, r1, r2, r3773}774type RequesterReturnElidedGetExpectation struct {775 call *mock.Call776}777func (_e *RequesterReturnElidedExpectation) Get(path string) *RequesterReturnElidedGetExpectation {778 return &RequesterReturnElidedGetExpectation{779 call: _e.mock.On("Get", path),780 }781}782func (_e *RequesterReturnElidedGetExpectation) ToReturn(a int, b int, c int, err error) *mock.Call {783 return _e.call.Return(a, b, c, err)784}785`786 s.checkGeneration(787 filepath.Join(fixturePath, "requester_ret_elided.go"),788 "RequesterReturnElided", false, expected,789 )790}791func (s *GeneratorSuite) TestGeneratorVariadicArgs() {792 // Read the expected output from a "golden" file that we can also import in CompatSuite793 // to asserts its actual behavior.794 //795 // To regenerate the golden file: make fixture796 expectedBytes, err := ioutil.ReadFile(filepath.Join(fixturePath, "mocks", "requester_variadic.go"))797 s.NoError(err)798 expected := string(expectedBytes)799 expected = expected[strings.Index(expected, "// RequesterVariadic is"):]800 s.checkGeneration(801 filepath.Join(fixturePath, "requester_variadic.go"),802 "RequesterVariadic", false, expected,803 )804}805func (s *GeneratorSuite) TestGeneratorFuncType() {806 expected := `// Fooer is an autogenerated mock type for the Fooer type807type Fooer struct {808 mock.Mock809}810type FooerExpectation struct {811 mock *mock.Mock812}813func (_m *Fooer) Expect() *FooerExpectation {814 return &FooerExpectation{mock: &_m.Mock}815}816// Bar provides a mock function with given fields: f817func (_m *Fooer) Bar(f func([]int)) {818 _m.Called(f)819}820type FooerBarExpectation struct {821 call *mock.Call822}823func (_e *FooerExpectation) Bar(f func([]int)) *FooerBarExpectation {824 return &FooerBarExpectation{825 call: _e.mock.On("Bar", f),826 }827}828func (_e *FooerBarExpectation) ToReturn() *mock.Call {829 return _e.call.Return()830}831// Baz provides a mock function with given fields: path832func (_m *Fooer) Baz(path string) func(string) string {833 ret := _m.Called(path)834 var r0 func(string) string835 if rf, ok := ret.Get(0).(func(string) func(string) string); ok {836 r0 = rf(path)837 } else {838 if ret.Get(0) != nil {839 r0 = ret.Get(0).(func(string) string)840 }841 }842 return r0843}844type FooerBazExpectation struct {845 call *mock.Call846}847func (_e *FooerExpectation) Baz(path string) *FooerBazExpectation {848 return &FooerBazExpectation{849 call: _e.mock.On("Baz", path),850 }851}852func (_e *FooerBazExpectation) ToReturn(_a0 func(string) string) *mock.Call {853 return _e.call.Return(_a0)854}855// Foo provides a mock function with given fields: f856func (_m *Fooer) Foo(f func(string) string) error {857 ret := _m.Called(f)858 var r0 error859 if rf, ok := ret.Get(0).(func(func(string) string) error); ok {860 r0 = rf(f)861 } else {862 r0 = ret.Error(0)863 }864 return r0865}866type FooerFooExpectation struct {867 call *mock.Call868}869func (_e *FooerExpectation) Foo(f func(string) string) *FooerFooExpectation {870 return &FooerFooExpectation{871 call: _e.mock.On("Foo", f),872 }873}874func (_e *FooerFooExpectation) ToReturn(_a0 error) *mock.Call {875 return _e.call.Return(_a0)876}877`878 s.checkGeneration(879 filepath.Join(fixturePath, "func_type.go"), "Fooer", false, expected,880 )881}882func (s *GeneratorSuite) TestGeneratorChanType() {883 expected := `// AsyncProducer is an autogenerated mock type for the AsyncProducer type884type AsyncProducer struct {885 mock.Mock886}887type AsyncProducerExpectation struct {888 mock *mock.Mock889}890func (_m *AsyncProducer) Expect() *AsyncProducerExpectation {891 return &AsyncProducerExpectation{mock: &_m.Mock}892}893// Input provides a mock function with given fields:894func (_m *AsyncProducer) Input() chan<- bool {895 ret := _m.Called()896 var r0 chan<- bool897 if rf, ok := ret.Get(0).(func() chan<- bool); ok {898 r0 = rf()899 } else {900 if ret.Get(0) != nil {901 r0 = ret.Get(0).(chan<- bool)902 }903 }904 return r0905}906type AsyncProducerInputExpectation struct {907 call *mock.Call908}909func (_e *AsyncProducerExpectation) Input() *AsyncProducerInputExpectation {910 return &AsyncProducerInputExpectation{911 call: _e.mock.On("Input"),912 }913}914func (_e *AsyncProducerInputExpectation) ToReturn(_a0 chan<- bool) *mock.Call {915 return _e.call.Return(_a0)916}917// Output provides a mock function with given fields:918func (_m *AsyncProducer) Output() <-chan bool {919 ret := _m.Called()920 var r0 <-chan bool921 if rf, ok := ret.Get(0).(func() <-chan bool); ok {922 r0 = rf()923 } else {924 if ret.Get(0) != nil {925 r0 = ret.Get(0).(<-chan bool)926 }927 }928 return r0929}930type AsyncProducerOutputExpectation struct {931 call *mock.Call932}933func (_e *AsyncProducerExpectation) Output() *AsyncProducerOutputExpectation {934 return &AsyncProducerOutputExpectation{935 call: _e.mock.On("Output"),936 }937}938func (_e *AsyncProducerOutputExpectation) ToReturn(_a0 <-chan bool) *mock.Call {939 return _e.call.Return(_a0)940}941// Whatever provides a mock function with given fields:942func (_m *AsyncProducer) Whatever() chan bool {943 ret := _m.Called()944 var r0 chan bool945 if rf, ok := ret.Get(0).(func() chan bool); ok {946 r0 = rf()947 } else {948 if ret.Get(0) != nil {949 r0 = ret.Get(0).(chan bool)950 }951 }952 return r0953}954type AsyncProducerWhateverExpectation struct {955 call *mock.Call956}957func (_e *AsyncProducerExpectation) Whatever() *AsyncProducerWhateverExpectation {958 return &AsyncProducerWhateverExpectation{959 call: _e.mock.On("Whatever"),960 }961}962func (_e *AsyncProducerWhateverExpectation) ToReturn(_a0 chan bool) *mock.Call {963 return _e.call.Return(_a0)964}965`966 s.checkGeneration(967 filepath.Join(fixturePath, "async.go"), "AsyncProducer", false,968 expected,969 )970}971func (s *GeneratorSuite) TestGeneratorFromImport() {972 expected := `// MyReader is an autogenerated mock type for the MyReader type973type MyReader struct {974 mock.Mock975}976type MyReaderExpectation struct {977 mock *mock.Mock978}979func (_m *MyReader) Expect() *MyReaderExpectation {980 return &MyReaderExpectation{mock: &_m.Mock}981}982// Read provides a mock function with given fields: p983func (_m *MyReader) Read(p []byte) (int, error) {984 ret := _m.Called(p)985 var r0 int986 if rf, ok := ret.Get(0).(func([]byte) int); ok {987 r0 = rf(p)988 } else {989 r0 = ret.Get(0).(int)990 }991 var r1 error992 if rf, ok := ret.Get(1).(func([]byte) error); ok {993 r1 = rf(p)994 } else {995 r1 = ret.Error(1)996 }997 return r0, r1998}999type MyReaderReadExpectation struct {1000 call *mock.Call1001}1002func (_e *MyReaderExpectation) Read(p []byte) *MyReaderReadExpectation {1003 return &MyReaderReadExpectation{1004 call: _e.mock.On("Read", p),1005 }1006}1007func (_e *MyReaderReadExpectation) ToReturn(n int, err error) *mock.Call {1008 return _e.call.Return(n, err)1009}1010`1011 s.checkGeneration(1012 filepath.Join(fixturePath, "io_import.go"), "MyReader", false,1013 expected,1014 )1015}1016func (s *GeneratorSuite) TestGeneratorComplexChanFromConsul() {1017 expected := `// ConsulLock is an autogenerated mock type for the ConsulLock type1018type ConsulLock struct {1019 mock.Mock1020}1021type ConsulLockExpectation struct {1022 mock *mock.Mock1023}1024func (_m *ConsulLock) Expect() *ConsulLockExpectation {1025 return &ConsulLockExpectation{mock: &_m.Mock}1026}1027// Lock provides a mock function with given fields: _a01028func (_m *ConsulLock) Lock(_a0 <-chan struct{}) (<-chan struct{}, error) {1029 ret := _m.Called(_a0)1030 var r0 <-chan struct{}1031 if rf, ok := ret.Get(0).(func(<-chan struct{}) <-chan struct{}); ok {1032 r0 = rf(_a0)1033 } else {1034 if ret.Get(0) != nil {1035 r0 = ret.Get(0).(<-chan struct{})1036 }1037 }1038 var r1 error1039 if rf, ok := ret.Get(1).(func(<-chan struct{}) error); ok {1040 r1 = rf(_a0)1041 } else {1042 r1 = ret.Error(1)1043 }1044 return r0, r11045}1046type ConsulLockLockExpectation struct {1047 call *mock.Call1048}1049func (_e *ConsulLockExpectation) Lock(_a0 <-chan struct{}) *ConsulLockLockExpectation {1050 return &ConsulLockLockExpectation{1051 call: _e.mock.On("Lock", _a0),1052 }1053}1054func (_e *ConsulLockLockExpectation) ToReturn(_a0 <-chan struct{}, _a1 error) *mock.Call {1055 return _e.call.Return(_a0, _a1)1056}1057// Unlock provides a mock function with given fields:1058func (_m *ConsulLock) Unlock() error {1059 ret := _m.Called()1060 var r0 error1061 if rf, ok := ret.Get(0).(func() error); ok {1062 r0 = rf()1063 } else {1064 r0 = ret.Error(0)1065 }1066 return r01067}1068type ConsulLockUnlockExpectation struct {1069 call *mock.Call1070}1071func (_e *ConsulLockExpectation) Unlock() *ConsulLockUnlockExpectation {1072 return &ConsulLockUnlockExpectation{1073 call: _e.mock.On("Unlock"),1074 }1075}1076func (_e *ConsulLockUnlockExpectation) ToReturn(_a0 error) *mock.Call {1077 return _e.call.Return(_a0)1078}1079`1080 s.checkGeneration(1081 filepath.Join(fixturePath, "consul.go"), "ConsulLock", false, expected,1082 )1083}1084func (s *GeneratorSuite) TestGeneratorForEmptyInterface() {1085 expected := `// Blank is an autogenerated mock type for the Blank type1086type Blank struct {1087 mock.Mock1088}1089type BlankExpectation struct {1090 mock *mock.Mock1091}1092func (_m *Blank) Expect() *BlankExpectation {1093 return &BlankExpectation{mock: &_m.Mock}1094}1095// Create provides a mock function with given fields: x1096func (_m *Blank) Create(x interface{}) error {1097 ret := _m.Called(x)1098 var r0 error1099 if rf, ok := ret.Get(0).(func(interface{}) error); ok {1100 r0 = rf(x)1101 } else {1102 r0 = ret.Error(0)1103 }1104 return r01105}1106type BlankCreateExpectation struct {1107 call *mock.Call1108}1109func (_e *BlankExpectation) Create(x interface{}) *BlankCreateExpectation {1110 return &BlankCreateExpectation{1111 call: _e.mock.On("Create", x),1112 }1113}1114func (_e *BlankCreateExpectation) ToReturn(_a0 error) *mock.Call {1115 return _e.call.Return(_a0)1116}1117`1118 s.checkGeneration(1119 filepath.Join(fixturePath, "empty_interface.go"), "Blank", false,1120 expected,1121 )1122}1123func (s *GeneratorSuite) TestGeneratorForMapFunc() {1124 expected := `// MapFunc is an autogenerated mock type for the MapFunc type1125type MapFunc struct {1126 mock.Mock1127}1128type MapFuncExpectation struct {1129 mock *mock.Mock1130}1131func (_m *MapFunc) Expect() *MapFuncExpectation {1132 return &MapFuncExpectation{mock: &_m.Mock}1133}1134// Get provides a mock function with given fields: m1135func (_m *MapFunc) Get(m map[string]func(string) string) error {1136 ret := _m.Called(m)1137 var r0 error1138 if rf, ok := ret.Get(0).(func(map[string]func(string) string) error); ok {1139 r0 = rf(m)1140 } else {1141 r0 = ret.Error(0)1142 }1143 return r01144}1145type MapFuncGetExpectation struct {1146 call *mock.Call1147}1148func (_e *MapFuncExpectation) Get(m map[string]func(string) string) *MapFuncGetExpectation {1149 return &MapFuncGetExpectation{1150 call: _e.mock.On("Get", m),1151 }1152}1153func (_e *MapFuncGetExpectation) ToReturn(_a0 error) *mock.Call {1154 return _e.call.Return(_a0)1155}1156`1157 s.checkGeneration(1158 filepath.Join(fixturePath, "map_func.go"), "MapFunc", false, expected,1159 )1160}1161func (s *GeneratorSuite) TestGeneratorForMethodUsingInterface() {1162 expected := `// UsesOtherPkgIface is an autogenerated mock type for the UsesOtherPkgIface type1163type UsesOtherPkgIface struct {1164 mock.Mock1165}1166type UsesOtherPkgIfaceExpectation struct {1167 mock *mock.Mock1168}1169func (_m *UsesOtherPkgIface) Expect() *UsesOtherPkgIfaceExpectation {1170 return &UsesOtherPkgIfaceExpectation{mock: &_m.Mock}1171}1172// DoSomethingElse provides a mock function with given fields: obj1173func (_m *UsesOtherPkgIface) DoSomethingElse(obj test.Sibling) {1174 _m.Called(obj)1175}1176type UsesOtherPkgIfaceDoSomethingElseExpectation struct {1177 call *mock.Call1178}1179func (_e *UsesOtherPkgIfaceExpectation) DoSomethingElse(obj test.Sibling) *UsesOtherPkgIfaceDoSomethingElseExpectation {1180 return &UsesOtherPkgIfaceDoSomethingElseExpectation{1181 call: _e.mock.On("DoSomethingElse", obj),1182 }1183}1184func (_e *UsesOtherPkgIfaceDoSomethingElseExpectation) ToReturn() *mock.Call {1185 return _e.call.Return()1186}1187`1188 s.checkGeneration(1189 filepath.Join(fixturePath, "mock_method_uses_pkg_iface.go"),1190 "UsesOtherPkgIface", false, expected,1191 )1192}1193func (s *GeneratorSuite) TestGeneratorForMethodUsingInterfaceInPackage() {1194 expected := `// MockUsesOtherPkgIface is an autogenerated mock type for the UsesOtherPkgIface type1195type MockUsesOtherPkgIface struct {1196 mock.Mock1197}1198type MockUsesOtherPkgIfaceExpectation struct {1199 mock *mock.Mock1200}1201func (_m *MockUsesOtherPkgIface) Expect() *MockUsesOtherPkgIfaceExpectation {1202 return &MockUsesOtherPkgIfaceExpectation{mock: &_m.Mock}1203}1204// DoSomethingElse provides a mock function with given fields: obj1205func (_m *MockUsesOtherPkgIface) DoSomethingElse(obj Sibling) {1206 _m.Called(obj)1207}1208type MockUsesOtherPkgIfaceDoSomethingElseExpectation struct {1209 call *mock.Call1210}1211func (_e *MockUsesOtherPkgIfaceExpectation) DoSomethingElse(obj Sibling) *MockUsesOtherPkgIfaceDoSomethingElseExpectation {1212 return &MockUsesOtherPkgIfaceDoSomethingElseExpectation{1213 call: _e.mock.On("DoSomethingElse", obj),1214 }1215}1216func (_e *MockUsesOtherPkgIfaceDoSomethingElseExpectation) ToReturn() *mock.Call {1217 return _e.call.Return()1218}1219`1220 s.checkGeneration(1221 filepath.Join(fixturePath, "mock_method_uses_pkg_iface.go"),1222 "UsesOtherPkgIface", true, expected,1223 )1224}1225func (s *GeneratorSuite) TestGeneratorWithAliasing() {1226 expected := `// Example is an autogenerated mock type for the Example type1227type Example struct {1228 mock.Mock1229}1230type ExampleExpectation struct {1231 mock *mock.Mock1232}1233func (_m *Example) Expect() *ExampleExpectation {1234 return &ExampleExpectation{mock: &_m.Mock}1235}1236// A provides a mock function with given fields:1237func (_m *Example) A() http.Flusher {1238 ret := _m.Called()1239 var r0 http.Flusher1240 if rf, ok := ret.Get(0).(func() http.Flusher); ok {1241 r0 = rf()1242 } else {1243 if ret.Get(0) != nil {1244 r0 = ret.Get(0).(http.Flusher)1245 }1246 }1247 return r01248}1249type ExampleAExpectation struct {1250 call *mock.Call1251}1252func (_e *ExampleExpectation) A() *ExampleAExpectation {1253 return &ExampleAExpectation{1254 call: _e.mock.On("A"),1255 }1256}1257func (_e *ExampleAExpectation) ToReturn(_a0 http.Flusher) *mock.Call {1258 return _e.call.Return(_a0)1259}1260// B provides a mock function with given fields: _a01261func (_m *Example) B(_a0 string) fixtureshttp.MyStruct {1262 ret := _m.Called(_a0)1263 var r0 fixtureshttp.MyStruct1264 if rf, ok := ret.Get(0).(func(string) fixtureshttp.MyStruct); ok {1265 r0 = rf(_a0)1266 } else {1267 r0 = ret.Get(0).(fixtureshttp.MyStruct)1268 }1269 return r01270}1271type ExampleBExpectation struct {1272 call *mock.Call1273}1274func (_e *ExampleExpectation) B(_a0 string) *ExampleBExpectation {1275 return &ExampleBExpectation{1276 call: _e.mock.On("B", _a0),1277 }1278}1279func (_e *ExampleBExpectation) ToReturn(_a0 fixtureshttp.MyStruct) *mock.Call {1280 return _e.call.Return(_a0)1281}1282`1283 s.checkGeneration(1284 filepath.Join(fixturePath, "same_name_imports.go"), "Example", false,1285 expected,1286 )1287}1288func (s *GeneratorSuite) TestGeneratorWithImportSameAsLocalPackageInpkgNoCycle() {1289 iface := s.getInterfaceFromFile("imports_same_as_package.go", "ImportsSameAsPackage")1290 pkg := iface.QualifiedName1291 gen := NewGenerator(iface, pkg, true)1292 gen.GeneratePrologue(pkg)1293 s.NotContains(gen.buf.String(), `import test "github.com/namely/mockery/mockery/fixtures/test"`)1294}1295func (s *GeneratorSuite) TestGeneratorWithImportSameAsLocalPackage() {1296 expected := `// ImportsSameAsPackage is an autogenerated mock type for the ImportsSameAsPackage type1297type ImportsSameAsPackage struct {1298 mock.Mock1299}1300type ImportsSameAsPackageExpectation struct {1301 mock *mock.Mock1302}1303func (_m *ImportsSameAsPackage) Expect() *ImportsSameAsPackageExpectation {1304 return &ImportsSameAsPackageExpectation{mock: &_m.Mock}1305}1306// A provides a mock function with given fields:1307func (_m *ImportsSameAsPackage) A() test.B {1308 ret := _m.Called()1309 var r0 test.B1310 if rf, ok := ret.Get(0).(func() test.B); ok {1311 r0 = rf()1312 } else {1313 r0 = ret.Get(0).(test.B)1314 }1315 return r01316}1317type ImportsSameAsPackageAExpectation struct {1318 call *mock.Call1319}1320func (_e *ImportsSameAsPackageExpectation) A() *ImportsSameAsPackageAExpectation {1321 return &ImportsSameAsPackageAExpectation{1322 call: _e.mock.On("A"),1323 }1324}1325func (_e *ImportsSameAsPackageAExpectation) ToReturn(_a0 test.B) *mock.Call {1326 return _e.call.Return(_a0)1327}1328// B provides a mock function with given fields:1329func (_m *ImportsSameAsPackage) B() fixtures.KeyManager {1330 ret := _m.Called()1331 var r0 fixtures.KeyManager1332 if rf, ok := ret.Get(0).(func() fixtures.KeyManager); ok {1333 r0 = rf()1334 } else {1335 if ret.Get(0) != nil {1336 r0 = ret.Get(0).(fixtures.KeyManager)1337 }1338 }1339 return r01340}1341type ImportsSameAsPackageBExpectation struct {1342 call *mock.Call1343}1344func (_e *ImportsSameAsPackageExpectation) B() *ImportsSameAsPackageBExpectation {1345 return &ImportsSameAsPackageBExpectation{1346 call: _e.mock.On("B"),1347 }1348}1349func (_e *ImportsSameAsPackageBExpectation) ToReturn(_a0 fixtures.KeyManager) *mock.Call {1350 return _e.call.Return(_a0)1351}1352// C provides a mock function with given fields: _a01353func (_m *ImportsSameAsPackage) C(_a0 fixtures.C) {1354 _m.Called(_a0)1355}1356type ImportsSameAsPackageCExpectation struct {1357 call *mock.Call1358}1359func (_e *ImportsSameAsPackageExpectation) C(_a0 fixtures.C) *ImportsSameAsPackageCExpectation {1360 return &ImportsSameAsPackageCExpectation{1361 call: _e.mock.On("C", _a0),1362 }1363}1364func (_e *ImportsSameAsPackageCExpectation) ToReturn() *mock.Call {1365 return _e.call.Return()1366}1367`1368 s.checkGeneration(1369 "imports_same_as_package.go", "ImportsSameAsPackage", false,1370 expected,1371 )1372}1373func (s *GeneratorSuite) TestPrologueWithImportSameAsLocalPackage() {1374 generator := s.getGenerator(1375 "imports_same_as_package.go", "ImportsSameAsPackage", false,1376 )1377 expected := `package mocks1378import fixtures "` + generator.iface.QualifiedName + `"1379import mock "github.com/stretchr/testify/mock"1380import test "github.com/namely/mockery/mockery/fixtures/test"1381`1382 s.checkPrologueGeneration(generator, expected)1383}1384func (s *GeneratorSuite) TestPrologueWithImportFromNestedInterface() {1385 generator := s.getGenerator(1386 "imports_from_nested_interface.go", "HasConflictingNestedImports", false,1387 )1388 expected := `package mocks1389import fixtureshttp "github.com/namely/mockery/mockery/fixtures/http"1390import http "net/http"1391import mock "github.com/stretchr/testify/mock"1392import test "github.com/namely/mockery/mockery/fixtures"1393`1394 s.checkPrologueGeneration(generator, expected)1395}1396func (s *GeneratorSuite) TestGeneratorForStructValueReturn() {1397 expected := `// A is an autogenerated mock type for the A type1398type A struct {1399 mock.Mock1400}1401type AExpectation struct {1402 mock *mock.Mock1403}1404func (_m *A) Expect() *AExpectation {1405 return &AExpectation{mock: &_m.Mock}1406}1407// Call provides a mock function with given fields:1408func (_m *A) Call() (test.B, error) {1409 ret := _m.Called()1410 var r0 test.B1411 if rf, ok := ret.Get(0).(func() test.B); ok {1412 r0 = rf()1413 } else {1414 r0 = ret.Get(0).(test.B)1415 }1416 var r1 error1417 if rf, ok := ret.Get(1).(func() error); ok {1418 r1 = rf()1419 } else {1420 r1 = ret.Error(1)1421 }1422 return r0, r11423}1424type ACallExpectation struct {1425 call *mock.Call1426}1427func (_e *AExpectation) Call() *ACallExpectation {1428 return &ACallExpectation{1429 call: _e.mock.On("Call"),1430 }1431}1432func (_e *ACallExpectation) ToReturn(_a0 test.B, _a1 error) *mock.Call {1433 return _e.call.Return(_a0, _a1)1434}1435`1436 s.checkGeneration(1437 filepath.Join(fixturePath, "struct_value.go"), "A", false,1438 expected,1439 )1440}1441func TestGeneratorSuite(t *testing.T) {1442 generatorSuite := new(GeneratorSuite)1443 suite.Run(t, generatorSuite)1444}...

Full Screen

Full Screen

mock.go

Source:mock.go Github

copy

Full Screen

...32 mock := &MockEmpty{ctrl: ctrl}33 mock.recorder = &MockEmptyMockRecorder{mock}34 return mock35}36// EXPECT returns an object that allows the caller to indicate expected use37func (m *MockEmpty) EXPECT() *MockEmptyMockRecorder {38 return m.recorder39}...

Full Screen

Full Screen

EXPECT

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 var i interface{}4 describe(i)5 describe(i)6 describe(i)7}8func describe(i interface{}) {9 fmt.Printf("(%v, %T)10}

Full Screen

Full Screen

EXPECT

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 var i interface{} = "hello"4 s := i.(string)5 fmt.Println(s)6 s, ok := i.(string)7 fmt.Println(s, ok)8 f, ok := i.(float64)9 fmt.Println(f, ok)10 fmt.Println(f)11}12panic: interface conversion: interface {} is string, not float6413main.main()

Full Screen

Full Screen

EXPECT

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 var i interface{}4 describe(i)5 describe(i)6 describe(i)7}8func describe(i interface{}) {9 fmt.Printf("(%v, %T)10}

Full Screen

Full Screen

EXPECT

Using AI Code Generation

copy

Full Screen

1import (2type empty_interface interface{}3func EXPECT(got, want empty_interface) {4 if !reflect.DeepEqual(got, want) {5 log.Fatalf("got %v, want %v", got, want)6 }7}8func main() {9 EXPECT(1, 1)10 EXPECT(1, 2)11 EXPECT("abc", "abc")12 EXPECT("abc", "def")13 fmt.Println("OK")14}15log.Fatalf(0x4a7a7c, 0x10, 0xc42004ff70, 0x1, 0x1)16main.EXPECT(0x3, 0x2, 0x0, 0x0)17main.main()18import (19type empty_interface interface{}20func EXPECT(got, want empty_interface) {21 if !reflect.DeepEqual(got, want) {22 log.Fatalf("got %v, want %v", got, want)23 }24}25func TestEXPECT(t *testing.T) {26 EXPECT(1, 1)27 EXPECT(1, 2)28 EXPECT("abc", "abc")29 EXPECT("abc", "def")30}31func main() {32 TestEXPECT(t)33 fmt.Println("OK")34}35log.Fatalf(0x4a7a7c, 0x10, 0xc42004ff70, 0x1, 0x1)

Full Screen

Full Screen

EXPECT

Using AI Code Generation

copy

Full Screen

1func (ei *empty_interface) EXPECT() {2 fmt.Println("In EXPECT method of empty_interface")3}4func (ei *empty_interface) EXPECT() {5 fmt.Println("In EXPECT method of empty_interface")6}7func (ei *empty_interface) EXPECT() {8 fmt.Println("In EXPECT method of empty_interface")9}10func (ei *empty_interface) EXPECT() {11 fmt.Println("In EXPECT method of empty_interface")12}13func (ei *empty_interface) EXPECT() {14 fmt.Println("In EXPECT method of empty_interface")15}16func (ei *empty_interface) EXPECT() {17 fmt.Println("In EXPECT method of empty_interface")18}19func (ei *empty_interface) EXPECT() {20 fmt.Println("In EXPECT method of empty_interface")21}22func (ei *empty_interface) EXPECT() {23 fmt.Println("In EXPECT method of empty_interface")24}25func (ei *empty_interface) EXPECT() {26 fmt.Println("In EXPECT method of empty_interface")27}28func (ei *empty_interface) EXPECT() {29 fmt.Println("In EXPECT method of empty_interface")30}31func (ei *empty_interface) EXPECT() {32 fmt.Println("In EXPECT method of empty_interface")33}34func (ei *empty_interface) EXPECT() {35 fmt.Println("In EXPECT method of empty_interface")36}37func (ei *empty_interface) EXPECT() {38 fmt.Println("In EXPECT method of

Full Screen

Full Screen

EXPECT

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var empty_interface interface{}4 fmt.Println(empty_interface)5 fmt.Printf("%T", empty_interface)6}7import (8func main() {9 var empty_interface interface{}10 fmt.Println(empty_interface)11 fmt.Printf("%T", empty_interface)12}13import (14func main() {15 var empty_interface interface{}16 fmt.Println(empty_interface)17 fmt.Printf("%T", empty_interface)18}

Full Screen

Full Screen

EXPECT

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 empty.EXPECT("hello")4 empty.EXPECT(1.0)5 empty.EXPECT(1)6 fmt.Println(empty)7}8import (9func main() {10 empty.EXPECT("hello")11 empty.EXPECT(1.0)12 empty.EXPECT(1)13 fmt.Println(empty)14}15import (16func main() {17 empty.EXPECT("hello")18 empty.EXPECT(1.0)19 empty.EXPECT(1)20 fmt.Println(empty)21}22import (23func main() {24 empty.EXPECT("hello")25 empty.EXPECT(1.0)26 empty.EXPECT(1)27 fmt.Println(empty)28}29import (30func main() {31 empty.EXPECT("hello")32 empty.EXPECT(1.0)33 empty.EXPECT(1)34 fmt.Println(empty)35}36import (37func main() {38 empty.EXPECT("hello")39 empty.EXPECT(1.0)40 empty.EXPECT(1)41 fmt.Println(empty)42}43import (44func main() {45 empty.EXPECT("hello")46 empty.EXPECT(1.0)47 empty.EXPECT(1)48 fmt.Println(empty)49}50import (51func main() {

Full Screen

Full Screen

EXPECT

Using AI Code Generation

copy

Full Screen

1func main(){2 var x interface{}3 fmt.Println(x)4}5func main(){6 var x interface{}7 fmt.Println(x)8}9func main(){10 var x interface{}11 fmt.Println(x)12}13func main(){14 var x interface{}15 fmt.Println(x)16}17func main(){18 var x interface{}19 fmt.Println(x)20}

Full Screen

Full Screen

EXPECT

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var empty_interface interface{}4 fmt.Println(empty_interface)5 fmt.Println(empty_interface)6 fmt.Println(empty_interface)7 fmt.Println(empty_interface)8 empty_interface = struct {9 }{name: "john", age: 20}10 fmt.Println(empty_interface)11 empty_interface = []int{1, 2, 3}12 fmt.Println(empty_interface)13 empty_interface = map[string]string{"name": "john", "age": "20"}14 fmt.Println(empty_interface)15 empty_interface = func() int {16 }17 fmt.Println(empty_interface)18 empty_interface = make(chan int)19 fmt.Println(empty_interface)20 empty_interface = new(int)21 fmt.Println(empty_interface)22 empty_interface = [3]int{1, 2, 3}23 fmt.Println(empty_interface)24}25{john 20}26import (27func main() {28 var empty_interface interface{}29 fmt.Println(empty_interface)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Mock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful