stripe / skycfg

Skycfg is an extension library for the Starlark language that adds support for constructing Protocol Buffer messages.
Apache License 2.0
648 stars 54 forks source link

Support passing in variables into tests #91

Closed seena-stripe closed 3 years ago

seena-stripe commented 3 years ago

Summary

Add option to pass in variables into executed tests.

Skycfg supports passing in variables during evaluation, but does not have a similar option to do so when evaluating tests. This works fine for tests on helper functions (where you'd have the caller pass relevant values as parameters rather than accessing the global ctx.vars directly) but meant you can't test the output of skycfg evaluation.

For example, if I wanted to assert that my proto's f_string is only 100 characters long:

def main(ctx):
    msg = MessageV3()
    msg.f_string = "hello, " + ctx.vars["name"]
    return [msg]

def test_main(ctx):
    msg = main(ctx)[0]
    ctx.assert(len(main) < 100)

Previously this would fail when running test_main because ctx.vars["name"] is not available. With this pr, it is possible to pass in the same variables when running tests.

Tests

Updated tests to skycfg_test to consider this case