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

Support mocking Nexus operation with operation reference #1683

Merged

Conversation

rodrigozhou
Copy link
Contributor

What was changed

Support mocking Nexus operation using nexus.OperationReference.

Why?

The user won't need to create a dummy implementation of Nexus operation to mock it.

Checklist

  1. Closes

  2. How was this tested:

  1. Any docs updates needed?

@Quinn-With-Two-Ns
Copy link
Contributor

It would be nice to have some tests using this new approach so we can see how it would be used.

@rodrigozhou
Copy link
Contributor Author

@Quinn-With-Two-Ns Added a test using it.

}
case testNexusOperationReference:
// This case covers both nexus.RegisterableOperation and nexus.OperationReference.
// All nexus.RegisterableOperation embeds nexus.UnimplementedOperation which
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: may want to setup a check to enforce this in the Go SDK since the Nexus SDK is not stable , but I guess your unit test would fail so maybe redundant.

Copy link
Member

@bergundy bergundy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor comments left. I'll leave it up to @Quinn-With-Two-Ns to approve.

internal/internal_workflow_testsuite.go Show resolved Hide resolved
internal/internal_workflow_testsuite.go Outdated Show resolved Hide resolved
internal/internal_workflow_testsuite.go Outdated Show resolved Hide resolved
mockErr,
))
}

mockResult := mockRet[0]
ret, ok := mockResult.(nexus.HandlerStartOperationResult[any])
result, ok := mockResult.(nexus.HandlerStartOperationResult[any])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised this works in Go as nexus.HandlerStartOperationResult[T] isn't assignable to nexus.HandlerStartOperationResult[any]. But looks like your test below is passing.

internal/internal_workflow_testsuite.go Show resolved Hide resolved
Copy link
Member

@bergundy bergundy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with comments. Nothing too major. Still want @Quinn-With-Two-Ns to do the last pass.

internal/internal_worker.go Show resolved Hide resolved
internal/internal_workflow_testsuite.go Outdated Show resolved Hide resolved
internal/internal_workflow_testsuite.go Outdated Show resolved Hide resolved
@rodrigozhou rodrigozhou merged commit 606be16 into rodrigozhou/nexus-test-mocks Oct 28, 2024
13 checks passed
@rodrigozhou rodrigozhou deleted the rodrigozhou/nexus-test-op-ref branch October 28, 2024 21:06
rodrigozhou added a commit that referenced this pull request Oct 28, 2024
* Support mocking Nexus operation with operation reference

* address comments

* address comments
rodrigozhou added a commit that referenced this pull request Oct 28, 2024
* Support for mocking nexus operations

* address comments

* add tests

* add nexus events listeners

* add test for nexus listeners

* address comments

* add assert nexus calls methods

* address static checks

* Support mocking Nexus operation with operation reference (#1683)

* Support mocking Nexus operation with operation reference

* address comments

* address comments
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.

3 participants