Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Kubespray
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
Kubespray
Commits
fb7c56e3
Unverified
Commit
fb7c56e3
authored
3 years ago
by
Kenichi Omichi
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add unit test for print_hostnames of inventory.py (#8558)
This adds a unit test for the function.
parent
2b79be68
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
contrib/inventory_builder/tests/test_inventory.py
+23
-0
23 additions, 0 deletions
contrib/inventory_builder/tests/test_inventory.py
with
23 additions
and
0 deletions
contrib/inventory_builder/tests/test_inventory.py
+
23
−
0
View file @
fb7c56e3
...
...
@@ -13,6 +13,7 @@
# under the License.
import
inventory
from
test
import
support
import
unittest
from
unittest
import
mock
...
...
@@ -26,6 +27,28 @@ if path not in sys.path:
import
inventory
# noqa
class
TestInventoryPrintHostnames
(
unittest
.
TestCase
):
@mock.patch
(
'
ruamel.yaml.YAML.load
'
)
def
test_print_hostnames
(
self
,
load_mock
):
mock_io
=
mock
.
mock_open
(
read_data
=
''
)
load_mock
.
return_value
=
OrderedDict
({
'
all
'
:
{
'
hosts
'
:
{
'
node1
'
:
{
'
ansible_host
'
:
'
10.90.0.2
'
,
'
ip
'
:
'
10.90.0.2
'
,
'
access_ip
'
:
'
10.90.0.2
'
},
'
node2
'
:
{
'
ansible_host
'
:
'
10.90.0.3
'
,
'
ip
'
:
'
10.90.0.3
'
,
'
access_ip
'
:
'
10.90.0.3
'
}}}})
with
mock
.
patch
(
'
builtins.open
'
,
mock_io
):
with
self
.
assertRaises
(
SystemExit
)
as
cm
:
with
support
.
captured_stdout
()
as
stdout
:
inventory
.
KubesprayInventory
(
changed_hosts
=
[
"
print_hostnames
"
],
config_file
=
"
file
"
)
self
.
assertEqual
(
"
node1 node2
\n
"
,
stdout
.
getvalue
())
self
.
assertEqual
(
cm
.
exception
.
code
,
0
)
class
TestInventory
(
unittest
.
TestCase
):
@mock.patch
(
'
inventory.sys
'
)
def
setUp
(
self
,
sys_mock
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment