-
Notifications
You must be signed in to change notification settings - Fork 248
feat(go): generated wiremock tests #9314
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
Conversation
return s; | ||
} | ||
return split[0].replace(INVALID_GO_IDENTIFIER_TOKEN, ""); | ||
return split.map((part) => part.replace(INVALID_GO_IDENTIFIER_TOKEN, "")).join(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't have go-wiremock
alias as go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we do need to be careful that this is not breaking behavior for package consumers.
But I don't think it is since it's just changing the alias we use in generated files, it isn't actual changing package names that the consumer might try to import and use without aliasing. But double check me on that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea as this is a writer change can this impact any other code generation parts?
@@ -0,0 +1,57 @@ | |||
package wiremock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is useful to run once for the entire test suite since initializing the wiremock test container does incur overhead. It can then be used in all individual test cases in the package
options?: Options | ||
): Promise<FernIr.dynamic.EndpointSnippetResponse> { | ||
return super.generate(request); | ||
return super.generate(request, options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since options is untyped and optional its the best way for me to pass in new options to the dynamic snippets endpoint generator to create "unit test case" snippets without breaking the abstract interface for all other users of DynamicSnippetsGenerator
}); | ||
} | ||
|
||
public static chainMethods( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could be convinced that a utility like this should be added onto the go.FuncInvocation
type itself... open to other ideas here but the usefulness should be clear
generators/go-v2/sdk/src/reference/EndpointSnippetsGenerator.ts
Outdated
Show resolved
Hide resolved
|
||
await context.snippetGenerator.populateSnippetsCache(); | ||
|
||
if (context.config.writeUnitTests) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it valid here to use the base config option writeUnitTest
(currently unused) or should I create a new more specific enableWireTests
etc flag? Will we ever want this specificity in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The realization is that writeUnitTests
is enabled by default across all generators (but check me on that) so in order to make this feature "opt-in" to begin with I will need to create a new customConfig
flag for the go generator probably called enableWireTests
as well!
0e09c33
to
4e98e59
Compare
return response.snippet; | ||
} | ||
|
||
private parseEndpointTestCaseSnippet(fileString: string): [string, Map<string, string>] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The endpoint snippet (with config.outputWiremockTests
) writes a complete test file for the single endpoint test method. I think its more meaningful to keep that behavior and then parse out the function body and imports in the consuming code. We can then collate the test methods by service
RUN git config --global user.name "fern" && git config --global user.email "[email protected]" | ||
|
||
COPY generators/go-v2/sdk/dist/cli.cjs /dist/cli.cjs | ||
COPY generators/go-v2/sdk/dist/ /dist/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is necessary for getting the AsIs
file behavior to work for the v2 go generator. The AsIs
files get copied into /dist/ along with the javascript bundle during pnpm dist:cli
.
@@ -0,0 +1,72 @@ | |||
package wiremock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the generated tests... which do pass!
I'm still looking into why this new seed test fails and why this new dependency adds a "toolchain" line:
|
Description
Linear ticket: FER-6290
Following the basic structure laid out for Java here create a
WireTestGenerator
that creates basic wire tests using go-wiremock. This feature will be enabled using thecustomConfig.enableWireTests
flag.TO-DO Items
See pending items in the [SDKs] Go Wire tests Linear project. Namely:
Refactor to follow pattern established for Java wire testsChanges Made
AsIs
file functionalityTesting