Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ivan Tyagov
slapos
Commits
cbdd26af
Commit
cbdd26af
authored
Sep 17, 2024
by
Thomas Gambier
🚴🏼
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos.cookbook: add test for switch_softwaretype recipe
See merge request
!1642
parent
d3b77b8d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
0 deletions
+62
-0
slapos/test/recipe/test_switch_softwaretype.py
slapos/test/recipe/test_switch_softwaretype.py
+62
-0
No files found.
slapos/test/recipe/test_switch_softwaretype.py
0 → 100644
View file @
cbdd26af
from
unittest.mock
import
MagicMock
import
unittest
from
slapos.recipe
import
switch_softwaretype
import
zc.buildout.testing
from
zc.buildout.buildout
import
MissingOption
,
MissingSection
class
SwitchSoftwaretypeTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
buildout
=
buildout
=
zc
.
buildout
.
testing
.
Buildout
()
buildout
[
'slap-configuration'
]
=
{
'slap-software-type'
:
'type1'
}
buildout
[
'switch-softwaretype'
]
=
{
'recipe'
:
'slapos.cookbook:switch-softwaretype'
,
'default'
:
'instance-default:output'
,
'type1'
:
'instance-type1:output'
,
'type2'
:
'instance-type2:output'
}
buildout
[
'instance-default'
]
=
{
'recipe'
:
'slapos.recipe.template:jinja2'
,
'output'
:
'instance-default.cfg'
}
buildout
[
'instance-type1'
]
=
{
'recipe'
:
'slapos.recipe.template:jinja2'
,
'output'
:
'instance-type1.cfg'
}
self
.
magick_sub_buildout
=
switch_softwaretype
.
SubBuildout
=
MagicMock
()
def
install_recipe
(
self
):
switch_softwaretype
.
Recipe
(
self
.
buildout
,
'switch-softwaretype'
,
self
.
buildout
[
'switch-softwaretype'
],
).
install
()
def
test_correct_type
(
self
):
self
.
install_recipe
()
self
.
magick_sub_buildout
.
assert_called_once
()
self
.
assertIn
(
'instance-type1.cfg'
,
self
.
magick_sub_buildout
.
call_args
.
args
)
def
test_type_section_not_present
(
self
):
self
.
buildout
[
'slap-configuration'
][
'slap-software-type'
]
=
'type2'
with
self
.
assertRaises
(
MissingSection
)
as
cm
:
self
.
install_recipe
()
self
.
magick_sub_buildout
.
assert_not_called
()
self
.
assertEqual
(
'instance-type2'
,
cm
.
exception
.
args
[
0
])
def
test_type_not_present
(
self
):
self
.
buildout
[
'slap-configuration'
][
'slap-software-type'
]
=
'type3'
with
self
.
assertRaises
(
MissingOption
)
as
cm
:
self
.
install_recipe
()
self
.
magick_sub_buildout
.
assert_not_called
()
self
.
assertIn
(
"This software type (type3) isn't mapped"
,
cm
.
exception
.
args
[
0
])
def
test_fallback_default
(
self
):
self
.
buildout
[
'slap-configuration'
][
'slap-software-type'
]
=
'RootSoftwareInstance'
with
self
.
assertLogs
(
'switch-softwaretype'
,
level
=
'INFO'
)
as
lc
:
self
.
install_recipe
()
self
.
magick_sub_buildout
.
assert_called_once
()
self
.
assertIn
(
"The software_type 'RootSoftwareInstance' is deprecated"
,
lc
.
output
[
0
])
self
.
assertIn
(
'instance-default.cfg'
,
self
.
magick_sub_buildout
.
call_args
.
args
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment