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

Wildcards support in test data #11

Open
argos83 opened this issue Jun 3, 2017 · 0 comments
Open

Wildcards support in test data #11

argos83 opened this issue Jun 3, 2017 · 0 comments

Comments

@argos83
Copy link
Owner

argos83 commented Jun 3, 2017

DataProviders should support processing wildcards when loading data.
A data wildcard is replaced at load time by the result of a function. Marvin should provide a set of built-in wildcards, but also allow custom wildcards to be plugged in.
Wildcards are defined as strings in data sources. But the result of its computation does not necessarily needs to result in a string, in which case a different type is returned, with the exception of the wildcard being surrounded prefixed and/or suffixed, in that case the result will be the string: prefix + str(value) + suffix.
A wildcard is represented as: OpeningTag + wildcard name + [:argument] + ClosingTag. I suggest using mustache's syntax (unless we think that may clash with real data). E.g.

a_key: {{wildcard_name:argument}}

when processed, marvin will look for a registered function under the name of wildcard_name which will be called with one string argument. If for some reason wildcard functions requires more than one argument, is up to them to parse the given argument into the required bits (e.g. comma splitting)
suggested built-in wildcards:

  • {{ENV:NAME}} or {{ENV:NAME:DEFAULT}}: replaced by the value of the environment variable NAME, or None, or DEFAULT
  • {{TIME}} or {{TIME:FORMAT}}: replaced by the current unix time, or a strftime string using the given FORMAT.
  • {{CONFIG:JsonPathQuery}}: the result of executing a jsonpath-like query on the context's config (evaluate if any of these libraries are good candidates for implementation: https://jmespath.readthedocs.io/en/latest/, https://github.com/kennknowles/python-jsonpath-rw, https://github.com/stefankoegl/python-json-pointer/blob/master/doc/tutorial.rst, https://github.com/akesterson/dpath-python)
  • {{RAND_ALPHA:length}}, {{RAND_ALPHA:minlength:maxlengt}} -> str
  • {{RAND_NUM:length}}, {{RAND_NUM:minlength:maxlengt}} -> str
  • {{RAND_ALPHANUM:length}}, {{RAND_ALPHANUM:minlength:maxlengt}} -> str
  • {{RAND_INT:min:max}} -> int
  • {{FILE:path}}: the result of reading the file at path (absolute or relative to cwd)
  • {{VAR:name}}: the value of the context var 'name'. Notice this can be processed at load time, but at access time.. this might be tricky, we might have to return a promise instead and resolve it per test script block.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant