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

rename mockgen variables like _ret1, _result and _params not to conflict with method args #124

Merged
merged 3 commits into from
Jun 20, 2023

Conversation

krrrr38
Copy link
Contributor

@krrrr38 krrrr38 commented Jun 18, 2023

Please make sure to open your PR against the develop branch.

v4 commits doesn't exists in develop branch, so PR is created into main.

Issue

closes #123

Generated code

diff
diff --git a/server/core/runtime/mocks/mock_status_updater.go b/server/core/runtime/mocks/mock_status_updater.go
index 63da713a..a8584dfb 100644
--- a/server/core/runtime/mocks/mock_status_updater.go
+++ b/server/core/runtime/mocks/mock_status_updater.go
@@ -30,15 +30,15 @@ func (mock *MockStatusUpdater) UpdateProject(ctx command.ProjectContext, cmdName
        if mock == nil {
                panic("mock must not be nil. Use myMock := NewMockStatusUpdater().")
        }
-       params := []pegomock.Param{ctx, cmdName, status, url, result}
-       pegomockResult := pegomock.GetGenericMockFrom(mock).Invoke("UpdateProject", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()})
-       var ret0 error
-       if len(pegomockResult) != 0 {
-               if pegomockResult[0] != nil {
-                       ret0 = pegomockResult[0].(error)
+       _params := []pegomock.Param{ctx, cmdName, status, url, result}
+       _result := pegomock.GetGenericMockFrom(mock).Invoke("UpdateProject", _params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()})
+       var _ret0 error
+       if len(_result) != 0 {
+               if _result[0] != nil {
+                       _ret0 = _result[0].(error)
                }
        }
-       return ret0
+       return _ret0
 }

 func (mock *MockStatusUpdater) VerifyWasCalledOnce() *VerifierMockStatusUpdater {
@@ -79,8 +79,8 @@ type VerifierMockStatusUpdater struct {
 }

 func (verifier *VerifierMockStatusUpdater) UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string, result *command.ProjectResult) *MockStatusUpdater_UpdateProject_OngoingVerification {
-       params := []pegomock.Param{ctx, cmdName, status, url, result}
-       methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "UpdateProject", params, verifier.timeout)
+       _params := []pegomock.Param{ctx, cmdName, status, url, result}
+       methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "UpdateProject", _params, verifier.timeout)
        return &MockStatusUpdater_UpdateProject_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations}
 }

@@ -95,26 +95,26 @@ func (c *MockStatusUpdater_UpdateProject_OngoingVerification) GetCapturedArgumen
 }
 }

 func (c *MockStatusUpdater_UpdateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []command.Name, _param2 []models.CommitStatus, _param3 []string, _param4 []*command.ProjectResult) {
-       params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
-       if len(params) > 0 {
+       _params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
+       if len(_params) > 0 {
                _param0 = make([]command.ProjectContext, len(c.methodInvocations))
-               for u, param := range params[0] {
+               for u, param := range _params[0] {
                        _param0[u] = param.(command.ProjectContext)
                }
                _param1 = make([]command.Name, len(c.methodInvocations))
-               for u, param := range params[1] {
+               for u, param := range _params[1] {
                        _param1[u] = param.(command.Name)
                }
                _param2 = make([]models.CommitStatus, len(c.methodInvocations))
-               for u, param := range params[2] {
+               for u, param := range _params[2] {
                        _param2[u] = param.(models.CommitStatus)
                }
                _param3 = make([]string, len(c.methodInvocations))
-               for u, param := range params[3] {
+               for u, param := range _params[3] {
                        _param3[u] = param.(string)
                }
                _param4 = make([]*command.ProjectResult, len(c.methodInvocations))
-               for u, param := range params[4] {
+               for u, param := range _params[4] {
                        _param4[u] = param.(*command.ProjectResult)
                }
        }
generated code
func (mock *MockStatusUpdater) UpdateProject(ctx command.ProjectContext, cmdName command.Name, status models.CommitStatus, url string, result *command.ProjectResult) error {
	if mock == nil {
		panic("mock must not be nil. Use myMock := NewMockStatusUpdater().")
	}
	_params := []pegomock.Param{ctx, cmdName, status, url, result}
	_result := pegomock.GetGenericMockFrom(mock).Invoke("UpdateProject", _params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()})
	var _ret0 error
	if len(_result) != 0 {
		if _result[0] != nil {
			_ret0 = _result[0].(error)
		}
	}
	return _ret0
}

func (c *MockStatusUpdater_UpdateProject_OngoingVerification) GetAllCapturedArguments() (_param0 []command.ProjectContext, _param1 []command.Name, _param2 []models.CommitStatus, _param3 []string, _param4 []*command.ProjectResult) {
	_params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations)
	if len(_params) > 0 {
		_param0 = make([]command.ProjectContext, len(c.methodInvocations))
		for u, param := range _params[0] {
			_param0[u] = param.(command.ProjectContext)
		}
		_param1 = make([]command.Name, len(c.methodInvocations))
		for u, param := range _params[1] {
			_param1[u] = param.(command.Name)
		}
		_param2 = make([]models.CommitStatus, len(c.methodInvocations))
		for u, param := range _params[2] {
			_param2[u] = param.(models.CommitStatus)
		}
		_param3 = make([]string, len(c.methodInvocations))
		for u, param := range _params[3] {
			_param3[u] = param.(string)
		}
		_param4 = make([]*command.ProjectResult, len(c.methodInvocations))
		for u, param := range _params[4] {
			_param4[u] = param.(*command.ProjectResult)
		}
	}
	return
}

@petergtz
Copy link
Owner

Such an obvious flaw! Thank you so much for fixing this, @krrrr38. Merging.

@petergtz petergtz merged commit d347194 into petergtz:main Jun 20, 2023
@krrrr38 krrrr38 deleted the mockgen-variables branch June 20, 2023 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pegomock generated code cannot use result and params method args which conflicts with generated code variable
2 participants