I’m trying to write some relation unit tests for this charm using the operator framework Test Harness.
This is my current code:
def test_main_with_relation(harness):
harness.set_leader(True)
harness.add_oci_resource('k8s-dashboard-image', {
'registrypath': 'kubernetesui/dashboard:v2.0.4',
'username': '',
'password': '',
})
rel_id = harness.add_relation("metrics-scraper", "dashboard-metrics-scraper")
harness.begin_with_initial_hooks()
assert isinstance(harness.charm.model.unit.status, WaitingStatus)
harness.add_relation_unit(rel_id, "dashboard-metrics-scraper/0")
harness.update_relation_data(rel_id, "k8s-dashboard/0",
{"service-name": "dashboard-metrics-scraper",
"service-port": "8000"})
assert isinstance(harness.charm.model.unit.status, ActiveStatus)
The relation in the charm uses the following interface. This interface should react to the relation_changed event which should be emmited by the update_relation_data method. Afterwards, the interface should emit the k8s_service_changed event and the charm should generate a new pod-spec with the new relation data and pass to an active state.
Unfortunately, with my current code the charm stays in a Waiting state. I’m wondering if this might be due to the k8s_service_changed event being ignored with the Harness or if I’m missing some steps.