ifcfg-rh/tests: add test for handling multiple occurances of a variable

This tests commit "ifcfg-rh: handle multiple definitions of the same key".
This commit is contained in:
Thomas Haller 2016-11-01 21:48:57 +01:00
parent c20b795547
commit 264e519779
4 changed files with 89 additions and 1 deletions

View file

@ -1932,7 +1932,9 @@ EXTRA_DIST += \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2 \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2.expected \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3 \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3.expected
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3.expected \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4 \
src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected
# make target dependencies can't have colons in their names, which ends up
# meaning that we can't add the alias files to EXTRA_DIST. They are instead

View file

@ -0,0 +1,32 @@
# test what happens with multiple defines of a name.
#
# Note that svGetValue() will return "l4x", which
# isn't correct in terms of shell-parsing. But we
# don't consider only line-by-line, thus this is
# expected.
#
# Also note that setting NAME will replace the last
# occurance, and delete all previous once.
#L1
NAME=l2
#L2
NAME=l3
#L4
NAME='
NAME=l4x
'
#Lx-1
NAME2=not-visible
#Lx-2
NAME2='invalid
#Lx-3
#Ly-1
NAME3='invalid
#Ly-2
NAME3=name3-value
#Ly-3

View file

@ -0,0 +1,27 @@
# test what happens with multiple defines of a name.
#
# Note that svGetValue() will return "l4x", which
# isn't correct in terms of shell-parsing. But we
# don't consider only line-by-line, thus this is
# expected.
#
# Also note that setting NAME will replace the last
# occurance, and delete all previous once.
#L1
#L2
#L4
NAME=set-by-test1
#NM: '
#Lx-1
#Lx-2
NAME2=set-by-test2
#Lx-3
#Ly-1
#Ly-2
NAME3=set-by-test3
#Ly-3

View file

@ -9026,12 +9026,38 @@ test_write_unknown (gconstpointer test_data)
gboolean success;
gs_free char *file_contents_out = NULL;
gs_free char *file_contents_exp = NULL;
gs_free char *tmp = NULL;
sv = svOpenFile (testfile, &error);
nmtst_assert_success (sv, error);
svFileSetName (sv, filename_tmp_1);
svFileSetModified (sv);
if (g_str_has_suffix (testfile, "ifcfg-test-write-unknown-4")) {
g_assert_cmpstr (svGetValue (sv, "NAME", &tmp), ==, "l4x");
nm_clear_g_free (&tmp);
g_assert_cmpstr (svGetValue (sv, "NAME2", &tmp), ==, NULL);
nm_clear_g_free (&tmp);
g_assert_cmpstr (svGetValue (sv, "NAME3", &tmp), ==, "name3-value");
nm_clear_g_free (&tmp);
svSetValue (sv, "NAME", "set-by-test1");
svSetValue (sv, "NAME2", "set-by-test2");
svSetValue (sv, "NAME3", "set-by-test3");
g_assert_cmpstr (svGetValue (sv, "NAME", &tmp), ==, "set-by-test1");
nm_clear_g_free (&tmp);
g_assert_cmpstr (svGetValue (sv, "NAME2", &tmp), ==, "set-by-test2");
nm_clear_g_free (&tmp);
g_assert_cmpstr (svGetValue (sv, "NAME3", &tmp), ==, "set-by-test3");
nm_clear_g_free (&tmp);
}
success = svWriteFile (sv, 0644, &error);
nmtst_assert_success (success, error);
@ -9229,6 +9255,7 @@ int main (int argc, char **argv)
g_test_add_data_func (TPATH "write-unknown/1", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-write-unknown-1", test_write_unknown);
g_test_add_data_func (TPATH "write-unknown/2", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-write-unknown-2", test_write_unknown);
g_test_add_data_func (TPATH "write-unknown/3", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-write-unknown-3", test_write_unknown);
g_test_add_data_func (TPATH "write-unknown/4", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-write-unknown-4", test_write_unknown);
g_test_add_func (TPATH "vlan-trailing-spaces", test_read_vlan_trailing_spaces);