Skip to main content

validate_bench_name

Function validate_bench_name 

Source
pub fn validate_bench_name(name: &str) -> Result<(), ValidationError>
Expand description

Validate a benchmark name against the naming rules.

Returns Ok(()) when the name is valid, or a ValidationError describing why the name was rejected.

§Rules

  1. Must not be empty.
  2. Must not exceed BENCH_NAME_MAX_LEN bytes.
  3. Only lowercase ASCII, digits, _, ., -, and / are allowed.
  4. No empty path segments (leading, trailing, or consecutive /).
  5. No . or .. path segments (path traversal).

§Examples

use perfgate_validation::{validate_bench_name, ValidationError};

// ── Valid names ──────────────────────────────────────
assert!(validate_bench_name("my-bench").is_ok());
assert!(validate_bench_name("bench_v2").is_ok());
assert!(validate_bench_name("path/to/bench").is_ok());
assert!(validate_bench_name("bench.v1").is_ok());
assert!(validate_bench_name("123").is_ok());

// ── Invalid names ───────────────────────────────────
// Empty
assert!(matches!(
    validate_bench_name(""),
    Err(ValidationError::Empty),
));

// Uppercase
assert!(matches!(
    validate_bench_name("MyBench"),
    Err(ValidationError::InvalidCharacters { .. }),
));

// Path traversal
assert!(matches!(
    validate_bench_name("../bench"),
    Err(ValidationError::PathTraversal { .. }),
));

// Trailing slash (empty segment)
assert!(matches!(
    validate_bench_name("bench/"),
    Err(ValidationError::EmptySegment { .. }),
));