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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Romain Courteaud
slapos
Commits
54dcf459
Commit
54dcf459
authored
Jan 11, 2024
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
recipe/check_parameter: support multi lines values
parent
2db2895a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
8 deletions
+62
-8
slapos/recipe/check_parameter/__init__.py
slapos/recipe/check_parameter/__init__.py
+2
-4
slapos/recipe/check_parameter/template/check_parameter.py.in
slapos/recipe/check_parameter/template/check_parameter.py.in
+4
-4
slapos/test/recipe/test_check_parameter.py
slapos/test/recipe/test_check_parameter.py
+56
-0
No files found.
slapos/recipe/check_parameter/__init__.py
View file @
54dcf459
...
...
@@ -45,10 +45,8 @@ class Recipe(GenericBaseRecipe):
elif
self
.
options
.
get
(
'expected-type'
)
==
"ipv4"
:
template
=
self
.
getTemplateFilename
(
'check_ipv4.py.in'
)
else
:
config
[
"expected-value"
]
=
self
.
options
.
get
(
'expected-value'
)
config
[
"expected-not-value"
]
=
self
.
options
.
get
(
'expected-not-value'
)
config
[
"expected-value"
]
=
str
(
self
.
options
.
get
(
'expected-value'
,
''
))
config
[
"expected-not-value"
]
=
str
(
self
.
options
.
get
(
'expected-not-value'
,
''
))
template
=
self
.
getTemplateFilename
(
'check_parameter.py.in'
)
promise
=
self
.
createExecutable
(
...
...
slapos/recipe/check_parameter/template/check_parameter.py.in
View file @
54dcf459
...
...
@@ -5,14 +5,14 @@ from __future__ import print_function
import socket
import sys
value =
"%(value)s"
expected =
"%(expected-value)s"
not_expected =
"%(expected-not-value)s"
value =
%(value)r
expected =
%(expected-value)r
not_expected =
%(expected-not-value)r
if expected != "" and value != expected:
print("FAIL: %%s != %%s" %% (value, expected))
sys.exit(127)
if not_expected != "" and value == not_expected:
if not_expected != "" and value == not_expected:
print("FAIL: %%s == %%s" %% (value, not_expected))
sys.exit(127)
slapos/test/recipe/test_check_parameter.py
0 → 100644
View file @
54dcf459
import
os
import
subprocess
import
tempfile
import
unittest
import
zc.buildout.testing
from
slapos.recipe
import
check_parameter
class
TestCheckParameter
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
buildout
=
zc
.
buildout
.
testing
.
Buildout
()
def
_makeRecipe
(
self
,
options
):
path
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
).
name
self
.
addCleanup
(
os
.
unlink
,
path
)
options
.
setdefault
(
"path"
,
path
)
self
.
buildout
[
"check-parameter"
]
=
options
recipe
=
check_parameter
.
Recipe
(
self
.
buildout
,
"check-parameter"
,
self
.
buildout
[
"check-parameter"
]
)
return
recipe
def
test_expected_value_ok
(
self
):
script
=
self
.
_makeRecipe
({
"expected-value"
:
"foo"
,
"value"
:
"foo"
}).
install
()
subprocess
.
check_call
(
script
)
def
test_expected_value_not_ok
(
self
):
script
=
self
.
_makeRecipe
({
"expected-value"
:
"foo"
,
"value"
:
"bar"
}).
install
()
with
self
.
assertRaises
(
subprocess
.
CalledProcessError
)
as
e
:
subprocess
.
check_output
(
script
,
universal_newlines
=
True
)
self
.
assertEqual
(
e
.
exception
.
output
,
"FAIL: bar != foo
\
n
"
)
def
test_expected_value_multi_lines_ok
(
self
):
script
=
self
.
_makeRecipe
(
{
"expected-value"
:
"foo
\
n
bar"
,
"value"
:
"foo
\
n
bar"
}
).
install
()
subprocess
.
check_output
(
script
)
def
test_expected_value_multi_lines_not_ok
(
self
):
script
=
self
.
_makeRecipe
({
"expected-value"
:
"foo
\
n
bar"
,
"value"
:
"foo"
}).
install
()
with
self
.
assertRaises
(
subprocess
.
CalledProcessError
)
as
e
:
subprocess
.
check_output
(
script
,
universal_newlines
=
True
)
self
.
assertEqual
(
e
.
exception
.
output
,
"FAIL: foo != foo
\
n
bar
\
n
"
)
def
test_expected_not_value_ok
(
self
):
script
=
self
.
_makeRecipe
({
"expected-not-value"
:
"foo"
,
"value"
:
"bar"
}).
install
()
subprocess
.
check_call
(
script
)
def
test_expected_not_value_not_ok
(
self
):
script
=
self
.
_makeRecipe
({
"expected-not-value"
:
"foo"
,
"value"
:
"foo"
}).
install
()
with
self
.
assertRaises
(
subprocess
.
CalledProcessError
)
as
e
:
subprocess
.
check_output
(
script
,
universal_newlines
=
True
)
self
.
assertEqual
(
e
.
exception
.
output
,
"FAIL: foo == foo
\
n
"
)
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