TT#33030 allow overwriting entire subkeys with similar types

Change-Id: I70b5b94cd6c5234f2a8b09fd2d4ebca488e5a31f
changes/33/19433/2
Richard Fuchs 8 years ago
parent 42357f59b6
commit 5eeb478d57

@ -90,6 +90,12 @@ for my \$component (split(/\\./, "${option}")) {
if (!defined(\$\$valref) || ref(\$valref) eq 'SCALAR') {
\$\$valref = ${value};
}
elsif (ref(\$\$valref) eq 'ARRAY' && ref(${value}) eq 'ARRAY') {
\$\$valref = ${value};
}
elsif (ref(\$\$valref) eq 'HASH' && ref(${value}) eq 'HASH') {
\$\$valref = ${value};
}
else {
print STDERR ("Key resolved to a " . ref(\$\$valref) . " reference; refusing to overwrite.\n");
exit(1);

@ -175,6 +175,27 @@ aaa:
assert out.returncode == 0
@pytest.mark.tt_33030
def test_set_action_overwrite_dictionary_subsection(ngcpcfgcli, tmpdir):
tmpfile = tmpdir.join("tmpfile.txt")
tmpfile.write('''---
aaa:
bbb:
eee: 'foobar'
fff: 'quux'
''')
out = ngcpcfgcli("set", str(tmpfile), "aaa.bbb={'ccc','123','ddd','567'}")
assert tmpfile.read() == '''---
aaa:
bbb:
ccc: '123'
ddd: '567'
'''
assert "" in out.stdout
assert "" in out.stderr
assert out.returncode == 0
@pytest.mark.tt_16903
def test_set_action_generate_list(ngcpcfgcli, tmpdir):
tmpfile = tmpdir.join("tmpfile.txt")
@ -193,6 +214,29 @@ aaa:
assert out.returncode == 0
@pytest.mark.tt_33030
def test_set_action_overwrite_list(ngcpcfgcli, tmpdir):
tmpfile = tmpdir.join("tmpfile.txt")
tmpfile.write('''---
aaa:
bbb:
- 5432
- 'foobar'
''')
out = ngcpcfgcli("set", str(tmpfile), "aaa.bbb=['ccc','123','ddd','567']")
assert tmpfile.read() == '''---
aaa:
bbb:
- ccc
- '123'
- ddd
- '567'
'''
assert "" in out.stdout
assert "" in out.stderr
assert out.returncode == 0
@pytest.mark.tt_16903
def test_set_action_add_list(ngcpcfgcli, tmpdir):
tmpfile = tmpdir.join("tmpfile.txt")

Loading…
Cancel
Save