Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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]>
@ldmonster
Copy link
Author

@hexdigest PTAL

@zcolleen
Copy link
Collaborator

zcolleen commented Feb 4, 2025

hey @ldmonster , sorry for late response and thanks for PR. It would be great if you could add a test on this behaviour and execute make generate to regenerate test mocks

Signed-off-by: Pavel Okhlopkov <[email protected]>
Signed-off-by: Pavel Okhlopkov <[email protected]>
@ldmonster
Copy link
Author

ldmonster commented Feb 5, 2025

hey @ldmonster , sorry for late response and thanks for PR. It would be great if you could add a test on this behaviour and execute make generate to regenerate test mocks

thank you!
added commit for generated files and one test with AnyContext in When/Then functions without args

@zcolleen zcolleen merged commit 6bd5c79 into gojuno:master Feb 5, 2025
1 check passed
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.

2 participants