charmed-kubernetes / pytest-operator

Apache License 2.0
7 stars 13 forks source link

Means of testing relation data #81

Open PietroPasotti opened 2 years ago

PietroPasotti commented 2 years ago

As a user, I would like to have some utility to test the contents of relation databags in itests.

Something like:


async def test_relate(ops_test: OpsTest):
    await ops_test.juju('relate', 'spring-music:ingress', 'traefik-k8s:ingress')
    async with ops_test.fast_forward():
        await ops_test.model.wait_for_idle(['traefik-k8s', 'spring-music'])

    data = await ops_test.get_relation_data(requirer_endpoint='spring-music/0:ingress',
                                   provider_endpoint='traefik-k8s/0:ingress')

    model = ops_test.current_alias
    assert data.requirer.application_data == {
        'host': f'spring-music.{model}.svc.cluster.local',
        'model': model,
        'name': 'spring-music/0',
        'port': '8080',
    }

    assert data.provider.unit_data == {'foo': 'bar'}