Skip to content

Commit

Permalink
Implement function newUuid
Browse files Browse the repository at this point in the history
  • Loading branch information
fabricereix committed Nov 22, 2024
1 parent d81b525 commit c964173
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 1 deletion.
4 changes: 4 additions & 0 deletions integration/hurl/tests_ok/function.hurl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
GET http://localhost:8000/function
[Query]
uuid: {{newUuid}}
HTTP 200
3 changes: 3 additions & 0 deletions integration/hurl/tests_ok/function.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'
hurl tests_ok/function.hurl
11 changes: 11 additions & 0 deletions integration/hurl/tests_ok/function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import re

from app import app
from flask import request


@app.route("/function")
def function():
uuid_pattern = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
assert re.match(uuid_pattern, request.args.get("uuid"))
return ""
3 changes: 3 additions & 0 deletions integration/hurl/tests_ok/function.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
set -Eeuo pipefail
hurl tests_ok/function.hurl
4 changes: 3 additions & 1 deletion packages/hurl/src/runner/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use crate::runner::error::{RunnerError, RunnerErrorKind};
use crate::runner::value::Value;
use crate::runner::VariableSet;

use super::function;

/// Evaluates the expression `expr` with `variables` map, returns a [`Value`] on success or an [`RunnerError`] .
pub fn eval(expr: &Expr, variables: &VariableSet) -> Result<Value, RunnerError> {
match &expr.kind {
Expand All @@ -34,7 +36,7 @@ pub fn eval(expr: &Expr, variables: &VariableSet) -> Result<Value, RunnerError>
Err(RunnerError::new(variable.source_info, kind, false))
}
}
ExprKind::Function(_function) => todo!(),
ExprKind::Function(fct) => function::eval(fct),
}
}

Expand Down
32 changes: 32 additions & 0 deletions packages/hurl/src/runner/function.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Hurl (https://hurl.dev)
* Copyright (C) 2024 Orange
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use hurl_core::ast::Function;
use uuid::Uuid;

use crate::runner::error::RunnerError;
use crate::runner::value::Value;

/// Evaluates the expression `expr` with `variables` map, returns a [`Value`] on success or an [`RunnerError`] .
pub fn eval(function: &Function) -> Result<Value, RunnerError> {
match &function {
Function::NewUuid => {
let uuid = Uuid::new_v4();
Ok(Value::String(uuid.to_string()))
}
}
}
1 change: 1 addition & 0 deletions packages/hurl/src/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ mod error;
mod event;
mod expr;
mod filter;
mod function;
mod hurl_file;
mod json;
mod multiline;
Expand Down

0 comments on commit c964173

Please sign in to comment.