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

[template] add when/then for functions without results #132

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ldmonster
Copy link

@ldmonster ldmonster commented Jan 17, 2025

Description

When i use minimock, i want to use When/Then functional for functions without result.
It helps me with checking strict different inputs.

Changes

Before:

We generate When/Then functions only for functions with result

After:

We generate When/Then functions for every functions with or without result

Example

Used struct from minimock repo.

User flow:

ContextAccepter.AcceptContext.When(context.TODO()).Then()
ContextAccepter.AcceptContext.When(context.Background()).Then()

Generated:

// generated same as for functions with result
func (mmAcceptContext *mContextAccepterMockAcceptContext) When(ctx context.Context) *ContextAccepterMockAcceptContextExpectation {
	if mmAcceptContext.mock.funcAcceptContext != nil {
		mmAcceptContext.mock.t.Fatalf("ContextAccepterMock.AcceptContext mock is already set by Set")
	}

	expectation := &ContextAccepterMockAcceptContextExpectation{
		mock:               mmAcceptContext.mock,
		params:             &ContextAccepterMockAcceptContextParams{ctx},
		expectationOrigins: ContextAccepterMockAcceptContextExpectationOrigins{origin: minimock.CallerInfo(1)},
	}
	mmAcceptContext.expectations = append(mmAcceptContext.expectations, expectation)
	return expectation
}

// here's removed input parameters
// this function used to save fluent-style 
func (e *ContextAccepterMockAcceptContextExpectation) Then() *ContextAccepterMock {
        // here's removed working with result
	return e.mock
}

Signed-off-by: Pavel Okhlopkov <[email protected]>
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.

1 participant