Update test harness inline with ops.testing
Remove bespoke charm config handling as this can now be done in ops.testing. Also update call to _TestingModelBackend to include charm config. Change-Id: I041ac4bfead12268c99c1773f0ca60f141e34047
This commit is contained in:
parent
e1155dc9a8
commit
017e56809d
@ -16,7 +16,6 @@
|
||||
|
||||
"""Module containing shared code to be used in a charms units tests."""
|
||||
|
||||
import yaml
|
||||
import inspect
|
||||
import json
|
||||
import ops
|
||||
@ -651,11 +650,6 @@ def get_harness(
|
||||
if os.path.isfile(metadata_file):
|
||||
with open(metadata_file) as f:
|
||||
charm_metadata = f.read()
|
||||
if not charm_config:
|
||||
config_file = f"{charm_dir}/config.yaml"
|
||||
if os.path.isfile(config_file):
|
||||
with open(config_file) as f:
|
||||
charm_config = f.read()
|
||||
|
||||
harness = Harness(
|
||||
charm_class,
|
||||
@ -663,18 +657,12 @@ def get_harness(
|
||||
config=charm_config
|
||||
)
|
||||
harness._backend = _OSTestingModelBackend(
|
||||
harness._unit_name, harness._meta
|
||||
harness._unit_name, harness._meta, harness._get_config(charm_config)
|
||||
)
|
||||
harness._model = model.Model(harness._meta, harness._backend)
|
||||
harness._framework = framework.Framework(
|
||||
":memory:", harness._charm_dir, harness._meta, harness._model
|
||||
)
|
||||
harness.set_model_name("test-model")
|
||||
if initial_charm_config:
|
||||
harness.update_config(initial_charm_config)
|
||||
else:
|
||||
defaults = {
|
||||
k: v['default']
|
||||
for k, v in yaml.safe_load(charm_config)['options'].items()}
|
||||
harness.update_config(defaults)
|
||||
|
||||
return harness
|
||||
|
@ -39,7 +39,7 @@ options:
|
||||
region:
|
||||
default: RegionOne
|
||||
description: Region
|
||||
type: str
|
||||
type: string
|
||||
"""
|
||||
|
||||
INITIAL_CHARM_CONFIG = {
|
||||
|
@ -128,7 +128,7 @@ class TestOSBaseOperatorAPICharm(test_utils.CharmTestCase):
|
||||
expect_entries = [
|
||||
'/bin/wsgi_admin',
|
||||
'hardpassword',
|
||||
'true',
|
||||
'True',
|
||||
'rabbit://my-service:rabbit.pass@10.0.0.13:5672/openstack',
|
||||
'rabbithost1.local',
|
||||
'svcpass1',
|
||||
@ -185,7 +185,7 @@ class TestOSBaseOperatorAPICharm(test_utils.CharmTestCase):
|
||||
'hardpassword')
|
||||
self.assertEqual(
|
||||
contexts.options.debug,
|
||||
'true')
|
||||
True)
|
||||
|
||||
def test_peer_leader_db(self) -> None:
|
||||
"""Test interacting with peer app db."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user