canonical / charm-relation-interfaces

https://canonical.github.io/charm-relation-interfaces/
Apache License 2.0
16 stars 47 forks source link

Rethink how interface tests are specified #68

Open PietroPasotti opened 1 year ago

PietroPasotti commented 1 year ago
          I know this is out of scope of this PR but the framework makes it non-trivial to check what is exactly validated. We're not asserting anything explicitly.

When I'm reviewing this test for example, I have a hard time figuring out, what exactly are we validating. The same goes for the next one where the devil's in the "schema=SchemaConfig.empty" detail.

_Originally posted by @gruyaume in https://github.com/canonical/charm-relation-interfaces/pull/57#discussion_r1174022340_

PietroPasotti commented 1 year ago

One possible API I have in mind at the moment is:

from interface_tester import register_test_case, Role, SchemaConfig

# minimal test case
register_test_case(
name='foo',
role=Role.requirer)

# schema
register_test_case(
name='bar',
role=Role.requirer,
schema=SchemaConfig.empty)

# validator, instead of the decorated function
register_test_case(
name='baz',
role=Role.provider,
validator=lambda output_state: output_state.status.unit.name == 'active')