Skip to content

Commit

Permalink
Merge pull request #50 from salt-extensions/azure-credentials
Browse files Browse the repository at this point in the history
Add pytest-ordering, Add test_absent func for second ip
  • Loading branch information
nicholasmhughes authored Mar 15, 2024
2 parents c9150b5 + 7397671 commit 9a47180
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 45 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ lint = [
]
tests = [
"pytest>=6.1.0",
"pytest-ordering>=0.6",
"pytest-salt-factories>=1.0.0rc19",
]

Expand Down
4 changes: 1 addition & 3 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ def tags():

@pytest.fixture(scope="session")
def resource_group():
yield "rg-salt-inttest-" + "".join(
random.choice(string.ascii_lowercase + string.digits) for _ in range(20)
)
yield "github"


@pytest.fixture(scope="session")
Expand Down
27 changes: 27 additions & 0 deletions tests/integration/states/test_public_ip_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,30 @@ def test_absent(salt_call_cli, public_ip_addr, resource_group, connection_auth):
assert data["changes"]["new"] == expected["changes"]["new"]
assert data["changes"]["old"]["name"] == expected["changes"]["old"]["name"]
assert data["result"] == expected["result"]


@pytest.mark.run(order=-3)
def test_absent_second_ip(salt_call_cli, public_ip_addr2, resource_group, connection_auth):
expected = {
"changes": {
"new": {},
"old": {
"name": public_ip_addr2,
},
},
"comment": f"Public IP address {public_ip_addr2} has been deleted.",
"name": public_ip_addr2,
"result": True,
}
ret = salt_call_cli.run(
"--local",
"state.single",
"azurerm_network.public_ip_address_absent",
name=public_ip_addr2,
resource_group=resource_group,
connection_auth=connection_auth,
)
data = list(ret.data.values())[0]
assert data["changes"]["new"] == expected["changes"]["new"]
assert data["changes"]["old"]["name"] == expected["changes"]["old"]["name"]
assert data["result"] == expected["result"]
51 changes: 9 additions & 42 deletions tests/integration/states/test_resource_group.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest


@pytest.mark.run(order=1)
def test_present(salt_call_cli, resource_group, location, connection_auth):
@pytest.mark.run(order=1, before="test_changes_remove_tag")
def test_changes_add_tag(salt_call_cli, resource_group, location, tags, connection_auth):
expected = {
"__id__": resource_group,
"__run_num__": 0,
Expand All @@ -11,23 +11,25 @@ def test_present(salt_call_cli, resource_group, location, connection_auth):
"new": {
"location": location,
"name": resource_group,
"type": "Microsoft.Resources/resourceGroups",
"properties": {"provisioning_state": "Succeeded"},
"tags": tags,
"type": "Microsoft.Resources/resourceGroups",
},
"old": {},
},
"comment": f"Resource group {resource_group} has been created.",
"name": resource_group,
"result": True,
}
# ret = resource.resource_group_present(resource_group, location, connection_auth=connection_auth)

ret = salt_call_cli.run(
"--local",
"state.single",
"azurerm_resource.resource_group_present",
name=resource_group,
location=location,
connection_auth=connection_auth,
tags=tags,
)
data = list(ret.data.values())[0]
data["changes"]["new"].pop("id")
Expand All @@ -36,8 +38,8 @@ def test_present(salt_call_cli, resource_group, location, connection_auth):
assert data == expected


@pytest.mark.run(order=1, after="test_present", before="test_absent")
def test_changes(salt_call_cli, resource_group, location, tags, connection_auth):
@pytest.mark.run(order=1, after="test_changes_add_tag")
def test_changes_remove_tag(salt_call_cli, resource_group, location, connection_auth):
expected = {
"__id__": resource_group,
"__run_num__": 0,
Expand All @@ -47,7 +49,6 @@ def test_changes(salt_call_cli, resource_group, location, tags, connection_auth)
"location": location,
"name": resource_group,
"properties": {"provisioning_state": "Succeeded"},
"tags": tags,
"type": "Microsoft.Resources/resourceGroups",
},
"old": {},
Expand All @@ -64,44 +65,10 @@ def test_changes(salt_call_cli, resource_group, location, tags, connection_auth)
name=resource_group,
location=location,
connection_auth=connection_auth,
tags=tags,
tags=None, # Set tags to None
)
data = list(ret.data.values())[0]
data["changes"]["new"].pop("id")
data.pop("duration")
data.pop("start_time")
assert data == expected


@pytest.mark.run(order=-1)
def test_absent(salt_call_cli, resource_group, location, tags, connection_auth):
expected = {
"__id__": resource_group,
"__run_num__": 0,
"__sls__": None,
"changes": {
"new": {},
"old": {
"location": location,
"name": resource_group,
"properties": {"provisioning_state": "Succeeded"},
"tags": tags,
"type": "Microsoft.Resources/resourceGroups",
},
},
"comment": f"Resource group {resource_group} has been deleted.",
"name": resource_group,
"result": True,
}
ret = salt_call_cli.run(
"--local",
"state.single",
"azurerm_resource.resource_group_absent",
name=resource_group,
connection_auth=connection_auth,
)
data = list(ret.data.values())[0]
data.pop("duration")
data.pop("start_time")
expected["changes"]["old"]["id"] = data["changes"]["old"]["id"]
assert data == expected

0 comments on commit 9a47180

Please sign in to comment.