Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove github.com/stretchr/testify/mock #749

Merged
merged 2 commits into from Feb 19, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev
Remove remaining uses of testify/mock
  • Loading branch information
bentranter committed Feb 18, 2020
commit d0532640f3c0d82335346ecabdd51f8d0f48f1b6
@@ -11,64 +11,71 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package do
package do_test

import (
"context"
"reflect"
"testing"

"context"
"github.com/digitalocean/doctl/do"
"github.com/digitalocean/godo"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

type GoDoAccountService struct {
mock.Mock
// MockAccountService is a mock of AccountService interface
type MockAccountService struct {
ctrl *gomock.Controller
recorder *MockAccountServiceMockRecorder
}

// Get provides a mock function with given fields: _a0
func (_m *GoDoAccountService) Get(_a0 context.Context) (*godo.Account, *godo.Response, error) {
ret := _m.Called(_a0)
// MockAccountServiceMockRecorder is the mock recorder for MockAccountService
type MockAccountServiceMockRecorder struct {
mock *MockAccountService
}

var r0 *godo.Account
if rf, ok := ret.Get(0).(func(context.Context) *godo.Account); ok {
r0 = rf(_a0)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*godo.Account)
}
}
// NewMockAccountService creates a new mock instance
func NewMockAccountService(ctrl *gomock.Controller) *MockAccountService {
mock := &MockAccountService{ctrl: ctrl}
mock.recorder = &MockAccountServiceMockRecorder{mock}
return mock
}

var r1 *godo.Response
if rf, ok := ret.Get(1).(func(context.Context) *godo.Response); ok {
r1 = rf(_a0)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*godo.Response)
}
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockAccountService) EXPECT() *MockAccountServiceMockRecorder {
return m.recorder
}

var r2 error
if rf, ok := ret.Get(2).(func(context.Context) error); ok {
r2 = rf(_a0)
} else {
r2 = ret.Error(2)
}
// Get mocks base method
func (m *MockAccountService) Get(arg0 context.Context) (*godo.Account, *godo.Response, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Get", arg0)
ret0, _ := ret[0].(*godo.Account)
ret1, _ := ret[1].(*godo.Response)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
}

return r0, r1, r2
// Get indicates an expected call of Get
func (mr *MockAccountServiceMockRecorder) Get(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockAccountService)(nil).Get), arg0)
}

func TestAccountServiceGet(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

gAccountSvc := &GoDoAccountService{}
gAccountSvc := NewMockAccountService(ctrl)

gAccount := &godo.Account{UUID: "uuid"}
gAccountSvc.On("Get", context.TODO()).Return(gAccount, nil, nil)
gAccountSvc.EXPECT().Get(context.TODO()).Return(gAccount, nil, nil)

client := &godo.Client{
Account: gAccountSvc,
}
as := NewAccountService(client)
as := do.NewAccountService(client)

account, err := as.Get()
assert.NoError(t, err)
@@ -11,64 +11,70 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package do
package do_test

import (
"context"
"reflect"
"testing"

"context"
"github.com/digitalocean/doctl/do"
"github.com/digitalocean/godo"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

type GoDoBalanceService struct {
mock.Mock
// MockBalanceService is a mock of BalanceService interface
type MockBalanceService struct {
ctrl *gomock.Controller
recorder *MockBalanceServiceMockRecorder
}

// Get provides a mock function with given fields: _a0
func (_m *GoDoBalanceService) Get(_a0 context.Context) (*godo.Balance, *godo.Response, error) {
ret := _m.Called(_a0)

var r0 *godo.Balance
if rf, ok := ret.Get(0).(func(context.Context) *godo.Balance); ok {
r0 = rf(_a0)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*godo.Balance)
}
}
// MockBalanceServiceMockRecorder is the mock recorder for MockBalanceService
type MockBalanceServiceMockRecorder struct {
mock *MockBalanceService
}

var r1 *godo.Response
if rf, ok := ret.Get(1).(func(context.Context) *godo.Response); ok {
r1 = rf(_a0)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*godo.Response)
}
}
// NewMockBalanceService creates a new mock instance
func NewMockBalanceService(ctrl *gomock.Controller) *MockBalanceService {
mock := &MockBalanceService{ctrl: ctrl}
mock.recorder = &MockBalanceServiceMockRecorder{mock}
return mock
}

var r2 error
if rf, ok := ret.Get(2).(func(context.Context) error); ok {
r2 = rf(_a0)
} else {
r2 = ret.Error(2)
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockBalanceService) EXPECT() *MockBalanceServiceMockRecorder {
return m.recorder
}

return r0, r1, r2
// Get mocks base method
func (m *MockBalanceService) Get(arg0 context.Context) (*godo.Balance, *godo.Response, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Get", arg0)
ret0, _ := ret[0].(*godo.Balance)
ret1, _ := ret[1].(*godo.Response)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
}

// Get indicates an expected call of Get
func (mr *MockBalanceServiceMockRecorder) Get(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockBalanceService)(nil).Get), arg0)
}
func TestBalanceServiceGet(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

gBalanceSvc := &GoDoBalanceService{}
gBalanceSvc := NewMockBalanceService(ctrl)

gBalance := &godo.Balance{AccountBalance: "12.34"}
gBalanceSvc.On("Get", context.TODO()).Return(gBalance, nil, nil)
gBalanceSvc.EXPECT().Get(context.TODO()).Return(gBalance, nil, nil)

client := &godo.Client{
Balance: gBalanceSvc,
}
as := NewBalanceService(client)
as := do.NewBalanceService(client)

balance, err := as.Get()
assert.NoError(t, err)
2 go.mod
@@ -10,7 +10,7 @@ require (
github.com/dustin/go-humanize v1.0.0
github.com/fatih/color v1.7.0
github.com/gobwas/glob v0.2.3
github.com/golang/mock v1.3.1
github.com/golang/mock v1.4.0
github.com/imdario/mergo v0.3.6 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/magiconair/properties v1.8.1 // indirect
7 go.sum
@@ -74,8 +74,8 @@ github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4er
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s=
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
github.com/golang/mock v1.4.0 h1:Rd1kQnQu0Hq3qvJppYSG0HtP+f5LPPUiDswTLiEegLg=
github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@@ -277,6 +277,7 @@ golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20191028164358-195ce5e7f934 h1:u/E0NqCIWRDAo9WCFo6Ko49njPFDLSd3z+X1HgWDMpE=
golang.org/x/sys v0.0.0-20191028164358-195ce5e7f934/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -338,6 +339,8 @@ k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E=
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f h1:GiPwtSzdP43eI1hpPCbROQCCIgCuiMMNF8YUVLF3vJo=
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.