CiscoCloud / distributive

Unit testing for the cloud
Apache License 2.0
147 stars 20 forks source link

Add ability of arguments to pull in external data #69

Open soellman opened 9 years ago

soellman commented 9 years ago

I've been thinking about this for a while. In order to have distributive work on dynamic data, we'd need to pull it from somewhere. Confd and a few other go-based projects use the pattern of evaluating go templates which in turn can run template functions to pull data in.

For instance:

"{{ etcdlookup('/config/key') }}"

And template fns are also handy for doing string processing to transform the value.

I think it'd be useful to have the ability to support single- and multi-value funcs to return what you need.

https://github.com/kelseyhightower/confd/blob/master/docs/templates.md

What do you think?

langston-barrett commented 9 years ago

@soellman Distributive has the ability to pull whole checklists from a remote URL, does that not cover lookups from etcd, etc? Would these functions to pull data in be a part of the Distributive code base? If so, what functions would you consider useful as a starting point?

soellman commented 9 years ago

The server on the end of the url still needs a process to construct the checks; if there were template funcs in distributive, it would essentially be running checks on dynamic arguments. By evaluating templates, you essentially get a little scripting language.

Probably an easy (and somewhat contrived) starting point would be - how can I make a check which tests that each and every directory in the PATH variable exists? That would entail getting env vars (getting remote data), and parsing the results (template func of "split"). I suppose this case also requires modifying the config parsing a little to allow for a single string var to represent an array internally.

Other useful starting template funcs - read from file, parse json. In a project I've been working on, I just add them as I have the need.

Here's another example of template funcs: https://github.com/jwilder/docker-gen/blob/master/template.go