- 
                Notifications
    
You must be signed in to change notification settings  - Fork 268
 
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
Changes from 12 commits
f18b07d
              50ffa00
              6b8d13a
              ea3a828
              2c57276
              c0682ee
              c30be70
              cdbae09
              bcf12ab
              4e98e59
              7bf6314
              3ae5f9a
              0245f97
              6c100b6
              fd49ee9
              7604ad4
              105ae3b
              248b65e
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package wiremock | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe 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  | 
||
| 
     | 
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "testing" | ||
| 
     | 
||
| gowiremock "github.com/wiremock/go-wiremock" | ||
| wiremocktestcontainersgo "github.com/wiremock/wiremock-testcontainers-go" | ||
| ) | ||
| 
     | 
||
| // Global test fixtures | ||
| var ( | ||
| WireMockContainer *wiremocktestcontainersgo.WireMockContainer | ||
| WireMockBaseURL string | ||
| WireMockClient *gowiremock.Client | ||
| ) | ||
| 
     | 
||
| // TestMain sets up shared test fixtures for all tests in this package | ||
| func TestMain(m *testing.M) { | ||
| // Setup shared WireMock container | ||
| ctx := context.Background() | ||
| container, err := wiremocktestcontainersgo.RunContainerAndStopOnCleanup( | ||
| ctx, | ||
| &testing.T{}, // We need a testing.T for the cleanup function, but we'll handle cleanup manually | ||
| wiremocktestcontainersgo.WithImage("docker.io/wiremock/wiremock:3.9.1"), | ||
| ) | ||
| if err != nil { | ||
| fmt.Printf("Failed to start WireMock container: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| 
     | 
||
| // Store global references | ||
| WireMockContainer = container | ||
| WireMockClient = container.Client | ||
| 
     | 
||
| // Get the base URL | ||
| baseURL, err := container.Endpoint(ctx, "") | ||
| if err != nil { | ||
| fmt.Printf("Failed to get WireMock container endpoint: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| WireMockBaseURL = "http://" + baseURL | ||
| 
     | 
||
| // Run all tests | ||
| code := m.Run() | ||
| 
     | 
||
| // This step is most likely unnecessary | ||
| // Cleanup | ||
| //if WireMockContainer != nil { | ||
| // WireMockContainer.Terminate(ctx) | ||
| //} | ||
| 
     | 
||
| // Exit with the same code as the tests | ||
| os.Exit(code) | ||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| import { | ||
| AbstractDynamicSnippetsGenerator, | ||
| AbstractFormatter, | ||
| FernGeneratorExec | ||
| FernGeneratorExec, | ||
| Options | ||
| } from "@fern-api/browser-compatible-base-generator"; | ||
| import { FernIr } from "@fern-api/dynamic-ir-sdk"; | ||
| import { DynamicSnippetsGeneratorContext } from "./context/DynamicSnippetsGeneratorContext"; | ||
| 
        
          
        
         | 
    @@ -27,13 +28,17 @@ export class DynamicSnippetsGenerator extends AbstractDynamicSnippetsGenerator< | |
| } | ||
| 
     | 
||
| public async generate( | ||
| request: FernIr.dynamic.EndpointSnippetRequest | ||
| request: FernIr.dynamic.EndpointSnippetRequest, | ||
| 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 commentThe 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   | 
||
| } | ||
| 
     | 
||
| public generateSync(request: FernIr.dynamic.EndpointSnippetRequest): FernIr.dynamic.EndpointSnippetResponse { | ||
| return super.generateSync(request); | ||
| public generateSync( | ||
| request: FernIr.dynamic.EndpointSnippetRequest, | ||
| options?: Options | ||
| ): FernIr.dynamic.EndpointSnippetResponse { | ||
| return super.generateSync(request, options); | ||
| } | ||
| 
     | 
||
| protected createSnippetGenerator(context: DynamicSnippetsGeneratorContext): EndpointSnippetGenerator { | ||
| 
          
            
          
           | 
    ||
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-wiremockalias asgoThere 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?