Skip to content
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

Suggestion: add random data generation helpers #606

Open
icepuma opened this issue Jun 6, 2022 · 5 comments
Open

Suggestion: add random data generation helpers #606

icepuma opened this issue Jun 6, 2022 · 5 comments
Labels
enhancement New feature or request topic: generators

Comments

@icepuma
Copy link

icepuma commented Jun 6, 2022

Hey folks,
awesome tool you wrote here!

As I use the tool for setting up demo data for my projects, I would find it cool to have a small set of helpers to e.g. create a random email or a random alphanumeric user name.

Those helpers could be used like:

# Create a new doggy thing with JSON body:
POST https://example.org/api/dogs
{
    "id": 0,
    "name": "{{random_alphanumeric(12)}}",
    "picture": "images/scottish-terrier.jpeg",
    "age": {{random_int()}},
    "breed": "Scottish Terrier",
    "location": "Lisco, Alabama"
}

I know that I could use the --variables functionality to inject variables and generate the random data outside of hurl, but I think this could come in handy for having self-contained .hurl - files.

If you like this idea or have more input, I would be happy to contribute the code myself! I wanted to let you guys know first and discuss it before I go for it!

Best regards
Stefan

@jcamiel
Copy link
Collaborator

jcamiel commented Jun 6, 2022

Hi, yes we plan to update the templates with expressions to add dynamic behavior. We have not settled on a syntax now (we’re currently rewriting our parser to support future uses cases) and this is directly in our roadmap of things to add. We’ve an issue about date support for templates, that has some ideas for syntax => #312

You’re welcome to add your use case and syntax proposition in the comments of this issue, so we take these into account. We definitively need more inputs and discussion before starting implementation.

@jcamiel
Copy link
Collaborator

jcamiel commented Dec 4, 2024

Hi @icepuma

we've introduced functions in Hurl 6.0.0

newUuid function can be used to create a UUID v4

POST https://example.org/api/foo
{
  "name": "foo",
  "email": "{{newUuid}}@test.com"
}

When run, the request body will be:

{
  "name": "foo",
  "email": "0531f78f-7f87-44be-a7f2-969a1c4e6d97@test.com"
}

We can expand functions for generating random number or string now, depending on the needs.

@jcamiel jcamiel added the open-to-contribution Open to external contributers label Jan 8, 2025
@fabricereix fabricereix removed the open-to-contribution Open to external contributers label Feb 13, 2025
@allestaire
Copy link

allestaire commented Feb 19, 2025

I guess it does not satisfy, it still cant create own behavior, or the documentation is not clear on how to use it?

@jcamiel
Copy link
Collaborator

jcamiel commented Feb 19, 2025

Hi @allestaire I don't understand your comment.

Actually, in Hurl 6.0.0, the only function that can produce random data is newUuid.

@allestaire
Copy link

Hi @allestaire I don't understand your comment.

Actually, in Hurl 6.0.0, the only function that can produce random data is newUuid.

Ahhh I see, thats sad, In my case, I wanted to select random item from an array which could not be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request topic: generators
Projects
None yet
Development

No branches or pull requests

4 participants