-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from canonical/open-port-support
ports api
- Loading branch information
Showing
8 changed files
with
137 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta" | |
[project] | ||
name = "ops-scenario" | ||
|
||
version = "5.0" | ||
version = "5.1.0" | ||
|
||
authors = [ | ||
{ name = "Pietro Pasotti", email = "[email protected]" } | ||
|
@@ -18,7 +18,7 @@ license.text = "Apache-2.0" | |
keywords = ["juju", "test"] | ||
|
||
dependencies = [ | ||
"ops>=2.0", | ||
"ops>=2.6", | ||
"PyYAML>=6.0.1", | ||
"typer==0.7.0", | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pytest | ||
from ops import CharmBase | ||
|
||
from scenario import Context, State | ||
from scenario.state import Port | ||
|
||
|
||
class MyCharm(CharmBase): | ||
META = {"name": "edgar"} | ||
|
||
|
||
@pytest.fixture | ||
def ctx(): | ||
return Context(MyCharm, meta=MyCharm.META) | ||
|
||
|
||
def test_open_port(ctx): | ||
def post_event(charm: CharmBase): | ||
charm.unit.open_port("tcp", 12) | ||
|
||
out = ctx.run("start", State(), post_event=post_event) | ||
port = out.opened_ports.pop() | ||
|
||
assert port.protocol == "tcp" | ||
assert port.port == 12 | ||
|
||
|
||
def test_close_port(ctx): | ||
def post_event(charm: CharmBase): | ||
assert charm.unit.opened_ports() | ||
charm.unit.close_port("tcp", 42) | ||
|
||
out = ctx.run("start", State(opened_ports={Port("tcp", 42)}), post_event=post_event) | ||
assert not out.opened_ports |