diff options
author | Thomas Haller <thaller@redhat.com> | 2016-11-01 21:48:57 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-11-09 12:07:35 +0100 |
commit | 264e519779cf3fa361df33b6dd77ee205504804b (patch) | |
tree | c8b205fbdcaa98185a5c0836a3a0d30a2aa957e6 | |
parent | c20b7955474dbc04fd8bdb85b1e4bff4803cf9ee (diff) | |
download | NetworkManager-264e519779cf3fa361df33b6dd77ee205504804b.tar.gz |
ifcfg-rh/tests: add test for handling multiple occurances of a variable
This tests commit "ifcfg-rh: handle multiple definitions of the same key".
4 files changed, 89 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am index 377a5a5e57..643a7ff118 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4 b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4 new file mode 100644 index 0000000000..2a0198d30b --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4 @@ -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 diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected new file mode 100644 index 0000000000..7f9a2d0616 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected @@ -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 diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 4cd7c4d270..0e7140e629 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -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); |