feat: Conver .http load tests to k6.io .js test files #26
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds functionality to convert .http files into Grafana k6 load testing scripts, enabling developers to reuse existing HTTP request definitions for performance testing.
Key changes:
- Added a
-convert k6command-line flag to trigger conversion to k6 format - Implemented a converter that preserves placeholders (converting
{{.VAR}}to${vars.VAR}), handles environment variables from.envfiles, and generates valid k6 JavaScript with proper options for iterations and delays - Included comprehensive documentation and test coverage for the conversion feature
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| cmd/httprunner/main.go | Added -convert flag and conversion mode logic to handle k6 conversion requests |
| cmd/httprunner/convert_k6.go | Created helper function to isolate k6 converter imports |
| converter/k6/generator.go | Core conversion logic transforming HTTP requests to k6 JavaScript scripts |
| converter/k6/generator_test.go | Unit tests verifying placeholder conversion, environment variable handling, and script generation |
| docs/specs/k6-coverter.md | Documentation explaining conversion feature with examples |
| examples/k6/loadtest.http | Example HTTP file demonstrating conversion capabilities |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -0,0 +1,84 @@ | |||
| # Conversion | |||
There was a problem hiding this comment.
Corrected spelling of 'coverter' to 'converter' in filename.
converter/k6/generator.go
Outdated
| b.WriteString(fmt.Sprintf(" sleep(%g);\n", float64(delay)/1000.0)) | ||
| } | ||
|
|
||
| _ = respVar |
There was a problem hiding this comment.
The variable respVar is assigned but never used. This appears to be dead code that should either be removed or utilized if it was intended for future functionality.
54dd8e0 to
b90a750
Compare
b90a750 to
d3e5f5e
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description:
This PR introduces a new feature: the ability to convert .http files into Grafana k6 scripts. This enables users to leverage existing .http files for load testing with k6.
Motivation:
Many developers already use .http files to define and test their APIs. Providing a conversion tool allows them to easily reuse these files for load testing with k6, reducing the effort required to set up performance tests.
What was changed:
-converttomain.goto trigger the conversion process.converter/k6package with aGeneratefunction that takes parsed .http requests and generates a k6 script.Generatefunction handles placeholders, environment variables (from .env files), and request details to create a valid k6 script.requireK6Generatehelper function to isolate the k6 conversion logic and avoid unnecessary imports when not used.cmd/httprunner/convert_k6.go: Contains therequireK6Generatehelper function.converter/k6/generator.go: Contains the core logic for converting .http requests to k6 scripts.converter/k6/generator_test.go: Contains unit tests for the k6 script generator.docs/specs/k6-coverter.md: Contains documentation on the k6 converter.examples/k6/loadtest.http: Example .http file to be converted to K6 format.Tests:
New unit tests have been added in
converter/k6/generator_test.goto verify the correct generation of k6 scripts, including placeholder handling, environment variable usage, and basic script structure.