fix: new tests

This commit is contained in:
egarette@silique.fr 2025-04-27 10:25:45 +02:00
parent 4a1b9ef5a5
commit fcafa64ff5
35 changed files with 447 additions and 15 deletions

View file

@ -32,7 +32,7 @@ def get_rougail_config(test_dir, namespace=False):
extras = list(test_dir.iterdir())
extras.sort()
for extra in extras:
if extra.name in ['rougail', 'rougail2']:
if extra.name in ['rougail', 'rougail2', 'file']:
continue
if extra.is_dir():
extra_dictionaries[extra.name] = [str(extra)]
@ -47,19 +47,23 @@ def get_rougail_config(test_dir, namespace=False):
return rougailconfig
def get_values_for_config(config, specify_dynamic_id=True, level="all"):
def get_values_for_config(config, specify_dynamic_id=True, level="all", use_unrestraint=True):
# level is "all" or "mandatories"
if use_unrestraint:
uconfig = config.unrestraint
else:
uconfig = config
excludes = []
get_excludes(config.unrestraint, excludes)
get_excludes(uconfig, excludes)
config.property.read_only()
root_config = config.unrestraint
root_config = uconfig
if level == 'all':
only = False
else:
only = True
values = {}
get_variables(root_config, root_config, values, only, excludes, specify_dynamic_id)
get_variables(root_config, root_config, values, only, excludes, specify_dynamic_id, use_unrestraint)
if not specify_dynamic_id:
for exclude in excludes:
_values = values
@ -85,7 +89,7 @@ def get_excludes(config, excludes):
get_excludes(option, excludes)
def get_value(variable, index, excludes):
def get_value(variable, index, excludes, config, use_unrestraint):
if 'force_store_value' in variable.property.get():
return variable.value.get()
tests = variable.information.get('test', None)
@ -118,13 +122,31 @@ def get_value(variable, index, excludes):
tests = ['192.168.1.6/32', '10.0.10.0/24']
else:
tests = ['192.168.1.6', '10.0.10.10']
elif variable.type() == 'email address':
tests = ["user1@domain1.lan", "user2@domain1.lan"]
elif variable.type() == 'file name':
tests = ["/directory1/file.txt", "/directory2/file.txt"]
elif variable.type() == 'URL':
tests = ['http://domain1.lan', 'https://domain2.lan']
elif variable.type() == 'password':
password = 'onE7vaLues_len1'
if variable.extra('max_len'):
password = password[:variable.extra('max_len')]
tests = [password]
else:
tests = ['string1', 'string2', 'string3']
if not variable.ismulti():
tests = tests[0]
elif index is not None and variable.isfollower() and variable.issubmulti() is False:
tests = tests[index]
if len(tests) > index:
tests = tests[index]
else:
tests = tests[0]
if not use_unrestraint:
config.property.read_write()
variable.value.set(tests)
if not use_unrestraint:
config.property.read_only()
# if tests == None:
# tests = ""
if index is not None and variable.isleader():
@ -132,8 +154,10 @@ def get_value(variable, index, excludes):
return tests
def get_variables(root_config, config, values, only, excludes, specify_dynamic_id, *, index=None, leader_is_mandatory=False):
def get_variables(root_config, config, values, only, excludes, specify_dynamic_id, use_unrestraint, *, index=None, leader_is_mandatory=False):
for idx, key in enumerate(config):
if not use_unrestraint and 'hidden' in key.property.get():
continue
if key.isoptiondescription():
if key.isleadership():
value = []
@ -142,16 +166,19 @@ def get_variables(root_config, config, values, only, excludes, specify_dynamic_i
leader_value = leader.value.get()
leader_is_mandatory = False
else:
leader_value = get_value(leader, None, excludes)
leader_value = get_value(leader, None, excludes, root_config, use_unrestraint)
leader_is_mandatory = True
has_value = False
for idx_, val in enumerate(leader_value):
value.append({})
get_variables(root_config, key, value[-1], only, excludes, specify_dynamic_id, index=idx_, leader_is_mandatory=leader_is_mandatory)
if value:
get_variables(root_config, key, value[-1], only, excludes, specify_dynamic_id, use_unrestraint, index=idx_, leader_is_mandatory=leader_is_mandatory)
if value[-1]:
has_value = True
if has_value:
values[key.name()] = value
else:
value = {}
get_variables(root_config, key, value, only, excludes, specify_dynamic_id)
get_variables(root_config, key, value, only, excludes, specify_dynamic_id, use_unrestraint)
if value:
values[key.name()] = value
else:
@ -166,7 +193,7 @@ def get_variables(root_config, config, values, only, excludes, specify_dynamic_i
if not only or mandatory:
if key.index() is not None and index is not None and index != key.index():
continue
value = get_value(key, index, excludes)
value = get_value(key, index, excludes, root_config, use_unrestraint)
if specify_dynamic_id or key.path(uncalculated=True) not in excludes:
values[key.name()] = value

View file

@ -0,0 +1,12 @@
---
version: '1.1'
var1:
description: the first variable
choices:
- a
- b
- c
var2:
description: the second variable
default:
variable: _.var1

View file

@ -0,0 +1,15 @@
---
version: '1.1'
var1: # a second variable
- a
- b
- c
var2:
description: a first variable
default: a
choices:
variable: _.var1
var3:
description: a third variable
default:
variable: _.var2

View file

@ -0,0 +1,16 @@
---
version: '1.1'
var1: # a second variable
- a
- b
- c
var2:
description: a first variable
default: a
choices:
variable: _.var1
family:
var3:
description: a third variable
default:
variable: __.var2

View file

@ -0,0 +1,17 @@
---
version: '1.1'
var1:
description: a first variable
regexp: "^#(?:[0-9a-f]{3}){1,2}$"
default: "#a1a1a1"
test:
- "#b1b1b1"
- "#b2b2b2"
var2:
description: a second variable
default:
variable: _.var1
test:
- "#b2b1b1"
- "#b3b2b2"

View file

@ -0,0 +1,24 @@
---
version: '1.1'
secret1:
description: the first variable
type: secret
params:
min_len: 10
secret2:
description: the second variable
type: secret
default: value
params:
max_len: 10
forbidden_char:
- $
- ^
secret3:
description: the third variable
type: secret
default: value
params:
max_len: 10
forbidden_char:
- $

View file

@ -0,0 +1,18 @@
---
version: '1.1'
var1:
description: the first variable
help: |-
Multi line
Help
With useful information
var2:
description: the second variable
help: >-
Multi line
Help
With useful information

View file

@ -0,0 +1,18 @@
---
version: '1.1'
var1:
description: the first <variable>
help: |-
Multi line
<Help>
With useful information
var2:
description: the second <variable>
help: >-
Multi line
<Help>
With useful information

View file

@ -0,0 +1,7 @@
---
version: '1.1'
variable:
description: a variable
mandatory: false
default:
type: namespace

View file

@ -0,0 +1,10 @@
---
version: '1.1'
variable:
description: a variable
mandatory: false
default:
jinja: '{{ namespace }}'
params:
namespace:
type: namespace

View file

@ -0,0 +1,6 @@
---
version: '1.1'
family:
var1:

View file

@ -0,0 +1,4 @@
---
version: 1.1
family:

View file

@ -0,0 +1,17 @@
---
version: 1.1
leadership:
description: a leadership
type: leadership
leader:
description: a leader
default:
- value1
- value2
follower:
description: a follower
default:
variable: _.leader

View file

@ -4,6 +4,6 @@ fam1: # first family
var: "no" # a variable
fam2: # second family
var:
description: a varaible
description: a variable
default:
variable: __.fam1.var

View file

@ -0,0 +1,17 @@
---
version: 1.1
leadership:
description: a leadership
type: leadership
leader:
description: a leader
default:
- value1
- value2
follower:
description: a follower
default:
- variable: _.leader

View file

@ -0,0 +1,18 @@
---
version: 1.1
leader:
type: leadership
leader:
default:
- a
- b
follower:
mandatory: false
variable:
mandatory: false
default:
variable: _.leader.follower

View file

@ -0,0 +1,16 @@
---
version: '1.1'
calculate:
description: a calculated variable
default:
- value1
- value2
leader:
description: a leadership
type: leadership
leader:
description: a leader
default:
variable: __.calculate
follower1: val11 # a follower
follower2: val21 # an other follower

View file

@ -0,0 +1,28 @@
---
version: 1.1
leadership_1:
description: a leadership
type: leadership
leader:
description: a leader
default:
- value1
- value2
follower:
description: a follower
leadership_2:
description: a second leadership
type: leadership
leader:
description: a leader
default:
variable: __.leadership_1.follower
follower:
description: a follower
default: val

View file

@ -0,0 +1,30 @@
---
version: 1.1
leadership_1:
description: a leadership
type: leadership
leader:
description: a leader
default:
- value1
- value2
follower:
description: a follower
leadership_2:
description: a second leadership
type: leadership
leader:
description: a leader
default:
- value1
- value2
follower:
description: a follower
default:
variable: __.leadership_1.leader

View file

@ -0,0 +1,23 @@
---
version: '1.1'
var: # A suffix variable
- val.1
- val.2
"dyn{{ identifier }}":
description: A dynamic family
dynamic:
variable: _.var
var1:
description: A dynamic variable
default:
type: identifier
var2:
description: A dynamic variable
default:
jinja: >-
{{ identifier }}
params:
identifier:
type: identifier

View file

@ -0,0 +1,12 @@
---
version: '1.1'
var: # A suffix variable
- Val1
- VAL2
"dyn{{ identifier }}":
description: A dynamic family
dynamic:
variable: _.var
var: # A dynamic variable

View file

@ -0,0 +1,24 @@
---
version: '1.1'
var1:
description: A suffix variable
multi: true
mandatory: false
test:
- val1
- val2
"dyn{{ identifier }}":
dynamic:
variable: _.var1
var:
description: A dynamic variable
disabled: true
var2:
description: A variable calculated
default:
variable: rougail.dynval1.var
optional: true

View file

@ -0,0 +1,23 @@
---
version: '1.1'
var2:
description: A variable calculated
default:
variable: rougail.dynval1.var
optional: true
var1:
description: A suffix variable
multi: true
mandatory: false
test:
- val1
- val2
"dyn{{ identifier }}":
dynamic:
variable: _.var1
var:
description: A dynamic variable

View file

@ -0,0 +1,25 @@
---
version: 1.1
var1:
description: A suffix variable
default:
- val1
- val2
dyn{{ identifier }}:
dynamic:
variable: _.var1
dyn{{ identifier }}:
dynamic:
variable: __.var1
var:
description: A dynamic variable
var2:
description: A variable calculated
unique: false
default:
variable: rougail.dyn{{ identifier }}.dynval1.var

View file

@ -0,0 +1,25 @@
---
version: 1.1
var1:
description: A suffix variable
default:
- val1
- val2
dyn{{ identifier }}:
dynamic:
variable: _.var1
dyn{{ identifier }}:
dynamic:
variable: __.var1
var:
description: A dynamic variable
var2:
description: A variable calculated
unique: false
default:
variable: rougail.dynval1.dyn{{ identifier }}.var

View file

@ -1,6 +1,6 @@
---
version: '1.1'
var: # a varaible
var: # a variable
- a
"dyn_{{ identifier }}":
dynamic: