aviaviavi / curl-runnings

A declarative test framework for quickly and easily writing integration tests against JSON APIs.
MIT License
157 stars 13 forks source link

Random string #35

Open meiremans opened 5 years ago

meiremans commented 5 years ago

Hi

Is there a way to generate a random string and use that string during the whole test run?

with kind regards

aviaviavi commented 5 years ago

Hi there!

Since curl runnings loads environment variables at the beginning of the test suite, using the ${RANDOM} environment variable will generate a random number, which you can use as a string in your tests. Will that work for you?

aviaviavi commented 5 years ago

You can also generate your own random strings and set them as environment variables that you reference in your curl-runnings tests. Nothing is built into the spec that has random functionality, but one could certainly be added if there's a good use case

meiremans commented 5 years ago

Hi Thanks for the quick reply. I actually tried something like that but didn't work on first try. I think it was something like ${RANDOM | tr '[0-9]' '[a-zA-Z]'} Anyway, probably my mistake in the syntax and will do it simply with ${RANDOM}.

My use case is this, make a random user, do things with it and set the user on inactive. As the API doesn't expose a real deletion of the user a second run will make the test fail because he cannot create that user again.

aviaviavi commented 5 years ago

Got it. So CR won't evaluate arbitrary bash expressions which is why RANDOM | tr '[0-9]' '[a-zA-Z]' wasn't working. Just environment variables as they are. So yeah for now, just RANDOM, or simply invoke curl runnings with something like USER_ID="$(RANDOM | tr '[0-9]' '[a-zA-Z]')" curl-runnings -f <your_file>

Sounds like having some random string + number generators natively supported by curl-runnings would be useful though, I do agree about that.

(Adding some labels to keep track of this. I think we have both a workaround for now as well as opportunities for curl-runnings to support this in a much more robust way)

meiremans commented 5 years ago

Thank you very much for your quick reply. I agree a random string and number generator would be useful. but the current workaround works fine for me.

On an other note, I am running this inside a docker container. Would it be useful if I push my dockerfile for other docker users?

aviaviavi commented 5 years ago

absolutely! please open a PR whenever you have the chance, thanks so much!