pub struct K6ScriptGenerator { /* private fields */ }Expand description
Generate k6 load test script
Implementations§
Source§impl K6ScriptGenerator
impl K6ScriptGenerator
Sourcepub fn new(config: K6Config, templates: Vec<RequestTemplate>) -> Self
pub fn new(config: K6Config, templates: Vec<RequestTemplate>) -> Self
Create a new k6 script generator
Sourcepub fn sanitize_k6_metric_name(name: &str) -> String
pub fn sanitize_k6_metric_name(name: &str) -> String
Sanitize a name into a valid k6 metric-name base, capped at
K6_METRIC_NAME_BASE_MAX_LEN characters.
k6 rejects metric names longer than 128 chars, and our templates
append suffixes like _latency, _errors, _stepN_latency —
reserve room for the longest suffix and truncate the base name
when needed. Truncation appends an 8-hex-char hash of the original
name so distinct long names produce distinct metric names.
Examples:
- “short_name” -> “short_name”
- 200-char OperationId -> “
_<8-hex-hash>”
Sourcepub fn sanitize_js_identifier(name: &str) -> String
pub fn sanitize_js_identifier(name: &str) -> String
Sanitize a name to be a valid JavaScript identifier
Replaces invalid characters (dots, spaces, special chars) with underscores. Ensures the identifier starts with a letter or underscore (not a number).
Examples:
- “billing.subscriptions.v1” -> “billing_subscriptions_v1”
- “get user” -> “get_user”
- “123invalid” -> “_123invalid”
Sourcepub fn validate_script(script: &str) -> Vec<String>
pub fn validate_script(script: &str) -> Vec<String>
Validate the generated k6 script for common issues
Checks for:
- Invalid metric names (contains dots or special characters)
- Invalid JavaScript variable names
- Missing required k6 imports
Returns a list of validation errors, empty if all checks pass.
Auto Trait Implementations§
impl Freeze for K6ScriptGenerator
impl RefUnwindSafe for K6ScriptGenerator
impl Send for K6ScriptGenerator
impl Sync for K6ScriptGenerator
impl Unpin for K6ScriptGenerator
impl UnsafeUnpin for K6ScriptGenerator
impl UnwindSafe for K6ScriptGenerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more