-
Notifications
You must be signed in to change notification settings - Fork 0
test: split e2e tests and add go-zero integration tests #11
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e6ec21a
test: split e2e_test.go into framework-specific test files
spencercjh 9842941
docs: update README.md
spencercjh 71a1390
fix: gozero e2e test field names to match actual types
spencercjh b9ad8e4
chore: update go.mod and go.sum for dependency upgrades
spencercjh 5ea17f5
chore(ci): update Go version to 1.26 and install goctl
spencercjh 1f022f7
Apply suggestion from @Copilot
spencercjh 193ec31
fix(test): address code review feedback for e2e tests
spencercjh 737d559
docs: add CI and code review badges to README.md
spencercjh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| //go:build e2e | ||
|
|
||
| package e2e_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/spencercjh/spec-forge/internal/executor" | ||
| ) | ||
|
|
||
| // TestE2E_ErrorHandling_CommandNotFound tests error handling when build tool is not found. | ||
| func TestE2E_ErrorHandling_CommandNotFound(t *testing.T) { | ||
| // Create a temp directory with pom.xml but no maven installed | ||
| tmpDir := t.TempDir() | ||
| pomPath := filepath.Join(tmpDir, "pom.xml") | ||
| if err := os.WriteFile(pomPath, []byte(`<project></project>`), 0o644); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| // Create target directory with a dummy spec (simulating pre-existing spec) | ||
| targetDir := filepath.Join(tmpDir, "target") | ||
| if err := os.Mkdir(targetDir, 0o755); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| ctx := context.Background() | ||
| exec := executor.NewExecutor() | ||
|
|
||
| // Try to run a non-existent command | ||
| _, err := exec.Execute(ctx, &executor.ExecuteOptions{ | ||
| Command: "nonexistent_command_12345", | ||
| Args: []string{}, | ||
| }) | ||
|
|
||
| if err == nil { | ||
| t.Fatal("Expected error for non-existent command") | ||
| } | ||
|
|
||
| // Verify it's a CommandNotFoundError | ||
| if _, ok := errors.AsType[*executor.CommandNotFoundError](err); !ok { | ||
| t.Logf("Got error type %T: %v", err, err) | ||
|
spencercjh marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,177 @@ | ||||||||||||||||
| //go:build e2e | ||||||||||||||||
|
|
||||||||||||||||
| package e2e_test | ||||||||||||||||
|
|
||||||||||||||||
| import ( | ||||||||||||||||
| "context" | ||||||||||||||||
| "os" | ||||||||||||||||
| "path/filepath" | ||||||||||||||||
| "testing" | ||||||||||||||||
| "time" | ||||||||||||||||
|
|
||||||||||||||||
| "github.com/spencercjh/spec-forge/internal/extractor" | ||||||||||||||||
| "github.com/spencercjh/spec-forge/internal/extractor/gozero" | ||||||||||||||||
| "github.com/spencercjh/spec-forge/internal/validator" | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| // TestE2E_GoZero_Generate tests the generate flow for a go-zero project. | ||||||||||||||||
| func TestE2E_GoZero_Generate(t *testing.T) { | ||||||||||||||||
| projectPath := "gozero-demo" | ||||||||||||||||
|
|
||||||||||||||||
| // Check if project exists | ||||||||||||||||
| if _, err := os.Stat(projectPath); os.IsNotExist(err) { | ||||||||||||||||
| t.Skip("go-zero demo project not found") | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // Check if go.mod exists | ||||||||||||||||
| goModPath := filepath.Join(projectPath, "go.mod") | ||||||||||||||||
| if _, err := os.Stat(goModPath); os.IsNotExist(err) { | ||||||||||||||||
| t.Skip("go.mod not found, skipping test") | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) | ||||||||||||||||
| defer cancel() | ||||||||||||||||
|
|
||||||||||||||||
| // Step 1: Detect project | ||||||||||||||||
| detector := gozero.NewDetector() | ||||||||||||||||
| info, err := detector.Detect(projectPath) | ||||||||||||||||
| if err != nil { | ||||||||||||||||
| t.Fatalf("Failed to detect project: %v", err) | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // Verify it's detected as go-zero | ||||||||||||||||
| if info.Framework != gozero.FrameworkGoZero { | ||||||||||||||||
| t.Errorf("Expected framework %s, got %s", gozero.FrameworkGoZero, info.Framework) | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // Verify go-zero specific info | ||||||||||||||||
| gozeroInfo, ok := info.FrameworkData.(*gozero.Info) | ||||||||||||||||
| if !ok { | ||||||||||||||||
| t.Fatal("Expected FrameworkData to be *gozero.Info") | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| if !gozeroInfo.HasGoZeroDeps { | ||||||||||||||||
| t.Error("Expected go-zero dependencies to be present") | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| if len(gozeroInfo.APIFiles) == 0 { | ||||||||||||||||
| t.Error("Expected at least one .api file to be found") | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| t.Logf("Detected go-zero project with %d API files: %v", len(gozeroInfo.APIFiles), gozeroInfo.APIFiles) | ||||||||||||||||
|
|
||||||||||||||||
| // Step 2: Patch (verify goctl availability) | ||||||||||||||||
| patcher := gozero.NewPatcher() | ||||||||||||||||
| patchResult, err := patcher.Patch(projectPath) | ||||||||||||||||
| if err != nil { | ||||||||||||||||
| t.Fatalf("Failed to patch project: %v", err) | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| if !patchResult.HasGoctl { | ||||||||||||||||
| t.Skip("goctl not found in PATH, skipping generation test") | ||||||||||||||||
| } | ||||||||||||||||
|
qodo-code-review[bot] marked this conversation as resolved.
spencercjh marked this conversation as resolved.
|
||||||||||||||||
|
|
||||||||||||||||
| t.Logf("goctl is available: %s", patchResult.GoctlVersion) | ||||||||||||||||
|
spencercjh marked this conversation as resolved.
|
||||||||||||||||
|
|
||||||||||||||||
| // Step 3: Generate OpenAPI spec | ||||||||||||||||
| gen := gozero.NewGenerator() | ||||||||||||||||
| result, err := gen.Generate(ctx, projectPath, info, &extractor.GenerateOptions{ | ||||||||||||||||
| Format: "yaml", | ||||||||||||||||
|
Comment on lines
+78
to
+79
|
||||||||||||||||
| result, err := gen.Generate(ctx, projectPath, info, &extractor.GenerateOptions{ | |
| Format: "yaml", | |
| outputDir := t.TempDir() | |
| result, err := gen.Generate(ctx, projectPath, info, &extractor.GenerateOptions{ | |
| Format: "yaml", | |
| OutputDir: outputDir, | |
| OutputFile: "openapi.yaml", |
spencercjh marked this conversation as resolved.
Outdated
qodo-code-review[bot] marked this conversation as resolved.
spencercjh marked this conversation as resolved.
spencercjh marked this conversation as resolved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| //go:build e2e | ||
|
|
||
| package e2e_test | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/spencercjh/spec-forge/internal/enricher/provider" | ||
| ) | ||
|
|
||
| // countingMockProvider tracks call counts for verification. | ||
| type countingMockProvider struct { | ||
| callCount int | ||
| responses map[string]string | ||
| } | ||
|
|
||
| func (m *countingMockProvider) Generate(ctx context.Context, prompt string) (string, error) { | ||
| m.callCount++ | ||
| if resp, ok := m.responses["default"]; ok { | ||
| return resp, nil | ||
| } | ||
| return `{"description": "Mock response"}`, nil | ||
| } | ||
|
|
||
| func (m *countingMockProvider) Name() string { | ||
| return "mock" | ||
| } | ||
|
|
||
| var _ provider.Provider = (*countingMockProvider)(nil) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| //go:build e2e | ||
|
|
||
| package e2e_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/spencercjh/spec-forge/internal/extractor" | ||
| "github.com/spencercjh/spec-forge/internal/extractor/spring" | ||
| "github.com/spencercjh/spec-forge/internal/validator" | ||
| ) | ||
|
|
||
| // TestE2E_GradleSpringBoot_Generate tests the generate flow for a Gradle Spring Boot project. | ||
| func TestE2E_GradleSpringBoot_Generate(t *testing.T) { | ||
| projectPath := "gradle-springboot-openapi-demo" | ||
|
|
||
| if _, err := os.Stat(projectPath); os.IsNotExist(err) { | ||
| t.Skip("Gradle Spring Boot demo project not found") | ||
| } | ||
|
|
||
| // Check if gradlew wrapper exists | ||
| gradlewPath := filepath.Join(projectPath, "gradlew") | ||
| if _, err := os.Stat(gradlewPath); os.IsNotExist(err) { | ||
| t.Skip("Gradle wrapper not found, skipping test") | ||
| } | ||
|
|
||
| ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) | ||
| defer cancel() | ||
|
|
||
| // Step 1: Detect project | ||
| detector := spring.NewDetector() | ||
| info, err := detector.Detect(projectPath) | ||
| if err != nil { | ||
| t.Fatalf("Failed to detect project: %v", err) | ||
| } | ||
|
|
||
| if info.BuildTool != spring.BuildToolGradle { | ||
| t.Errorf("Expected Gradle build tool, got %s", info.BuildTool) | ||
| } | ||
|
|
||
| // Step 2: Generate OpenAPI spec (uses gradlew wrapper) | ||
| gen := spring.NewGenerator() | ||
| result, err := gen.Generate(ctx, projectPath, info, &extractor.GenerateOptions{ | ||
| Format: "json", | ||
| SkipTests: true, | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("Failed to generate spec: %v", err) | ||
| } | ||
|
|
||
| // Step 3: Validate | ||
| v := validator.NewValidator() | ||
| validateResult, err := v.Validate(ctx, result.SpecFilePath) | ||
| if err != nil { | ||
| t.Fatalf("Failed to validate spec: %v", err) | ||
| } | ||
|
|
||
| if !validateResult.Valid { | ||
| t.Errorf("Generated spec is invalid: %v", validateResult.Errors) | ||
| } | ||
|
|
||
| t.Logf("Successfully generated valid OpenAPI spec at: %s", result.SpecFilePath) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.