2 # Copyright 2022 Canonical Ltd.
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
16 # For those usages not covered by the Apache License, Version 2.0 please
17 # contact: legal@canonical.com
19 # To get in touch with the maintainers, please contact:
20 # osm-charmers@lists.launchpad.net
22 # Learn more about testing at: https://juju.is/docs/sdk/testing
25 from ops
.model
import ActiveStatus
26 from ops
.testing
import Harness
27 from pytest_mock
import MockerFixture
29 from charm
import JujuSimplestreamsCharm
31 container_name
= "server"
32 service_name
= "server"
36 def harness(mocker
: MockerFixture
):
37 mocker
.patch("charm.KubernetesServicePatch", lambda x
, y
: None)
38 harness
= Harness(JujuSimplestreamsCharm
)
40 harness
.charm
.container
.make_dir("/etc/nginx", make_parents
=True)
45 def test_ready(harness
: Harness
):
46 harness
.charm
.on
.server_pebble_ready
.emit(container_name
)
47 assert harness
.charm
.unit
.status
== ActiveStatus()
50 def test_add_metadata_action(harness
: Harness
, mocker
: MockerFixture
):
51 harness
.set_leader(True)
52 remote_unit
= f
"{harness.charm.app.name}/1"
53 relation_id
= harness
.add_relation("peer", harness
.charm
.app
.name
)
54 harness
.add_relation_unit(relation_id
, remote_unit
)
57 "region": "microstack",
58 "auth-url": "localhost",
62 harness
.charm
._on
_add
_image
_metadata
_action
(event
)
63 # Harness not emitting relation changed event when in the action
64 # I update application data in the peer relation.
65 # Manually emitting it here:
66 relation
= harness
.charm
.model
.get_relation("peer")
67 harness
.charm
.on
["peer"].relation_changed
.emit(relation
)
68 assert harness
.charm
.container
.exists("/app/static/simplestreams/images/streams/v1/index.json")