Skip to content

Commit 8f78a31

Browse files
committed
Added test case for #63636 implementation.
1 parent f880fb9 commit 8f78a31

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FAKE-SSH-KEY
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"version": 4,
3+
"terraform_version": "1.2.3",
4+
"serial": 1,
5+
"lineage": "86545604-7463-4aa5-e9e8-a2a221de98d2",
6+
"outputs": {},
7+
"resources": [
8+
{
9+
"mode": "managed",
10+
"name": "example",
11+
"type": "salt_host",
12+
"provider": "provider.libvrt",
13+
"instances": [
14+
{
15+
"schema_version": 1,
16+
"attributes": {
17+
"host": "192.168.122.106",
18+
"id": "web0",
19+
"passwd": "linux",
20+
"salt_id": "web0",
21+
"timeout": "22",
22+
"user": "root"
23+
}
24+
},
25+
{
26+
"schema_version": 1,
27+
"attributes": {
28+
"host": "192.168.122.107",
29+
"id": "web1",
30+
"passwd": "linux",
31+
"salt_id": "web1",
32+
"timeout": "22",
33+
"user": "root",
34+
"priv": "tests/pytests/unit/roster/terraform.data/ssh/salt-ssh-custom.rsa"
35+
}
36+
}
37+
]
38+
},
39+
{
40+
"mode": "managed",
41+
"name": "example",
42+
"type": "non_salt_host",
43+
"provider": "provider.libvrt",
44+
"instances": [
45+
{
46+
"schema_version": 1,
47+
"attributes": {
48+
"host": "192.168.122.106",
49+
"id": "web0",
50+
"passwd": "linux",
51+
"salt_id": "web0",
52+
"timeout": "22",
53+
"user": "root"
54+
}
55+
}
56+
]
57+
}
58+
]
59+
}

tests/pytests/unit/roster/test_terraform.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ def roster_file_new():
2020
return pathlib.Path(__file__).parent / "terraform.data" / "terraform-new.tfstate"
2121

2222

23+
@pytest.fixture
24+
def roster_file_priv():
25+
""" Fixture containing a specified "priv" argument. """
26+
return pathlib.Path(__file__).parent / "terraform.data" / "terraform-new-specific-priv.tfstate"
27+
28+
2329
@pytest.fixture
2430
def pki_dir():
2531
return pathlib.Path(__file__).parent / "terraform.data"
@@ -154,6 +160,33 @@ def test_defaults_new_matching(pki_dir, roster_file_new):
154160
assert expected_result == ret
155161

156162

163+
def test_specified_priv(pki_dir, roster_file_priv):
164+
"""
165+
Test the output of a fixture tfstate file which contains libvirt
166+
resources using matching
167+
"""
168+
expected_result = {
169+
"web0": {
170+
"host": "192.168.122.106",
171+
"user": "root",
172+
"passwd": "linux",
173+
"timeout": 22,
174+
"priv": str(pki_dir / "ssh" / "salt-ssh.rsa"),
175+
},
176+
"web1": {
177+
"host": "192.168.122.107",
178+
"user": "root",
179+
"passwd": "linux",
180+
"timeout": 22,
181+
"priv": "tests/pytests/unit/roster/terraform.data/ssh/salt-ssh-custom.rsa",
182+
},
183+
}
184+
185+
with patch.dict(terraform.__opts__, {"roster_file": str(roster_file_priv)}):
186+
ret = terraform.targets("*")
187+
assert expected_result == ret
188+
189+
157190
def test_correct_handler_called_old():
158191
old_mock = patch.object(terraform, "_do__parse_old_state_file")
159192
new_mock = patch.object(terraform, "_do_parse_new_state_file")

0 commit comments

Comments
 (0)