From 28d61873962f0cefc192f32942e891ec4826df84 Mon Sep 17 00:00:00 2001 From: Nick Anderson Date: Thu, 11 Nov 2021 10:52:51 -0600 Subject: [PATCH] Added test that set_variable_values_ini does not error when keys are not present in promised section Ticket: CFE-3866 Changelog: None --- ..._error_when_keys_in_section_not_present.cf | 35 ++++++++++ ...or_when_keys_in_section_not_present.cf.sub | 70 +++++++++++++++++++ ..._keys_in_section_not_present.cf.sub.finish | 5 ++ ...n_keys_in_section_not_present.cf.sub.start | 4 ++ 4 files changed, 114 insertions(+) create mode 100644 tests/acceptance/lib/files/set_variable_values_ini_no_error_when_keys_in_section_not_present.cf create mode 100644 tests/acceptance/lib/files/set_variable_values_ini_no_error_when_keys_in_section_not_present.cf.sub create mode 100644 tests/acceptance/lib/files/set_variable_values_ini_no_error_when_keys_in_section_not_present.cf.sub.finish create mode 100644 tests/acceptance/lib/files/set_variable_values_ini_no_error_when_keys_in_section_not_present.cf.sub.start diff --git a/tests/acceptance/lib/files/set_variable_values_ini_no_error_when_keys_in_section_not_present.cf b/tests/acceptance/lib/files/set_variable_values_ini_no_error_when_keys_in_section_not_present.cf new file mode 100644 index 000000000..2d0eb27c5 --- /dev/null +++ b/tests/acceptance/lib/files/set_variable_values_ini_no_error_when_keys_in_section_not_present.cf @@ -0,0 +1,35 @@ +####################################################### +# +# Test bundle set_config_values_ini +# +####################################################### + +body common control +{ + inputs => { '../../default.cf.sub' }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; +} + +####################################################### + + +bundle agent test +{ + meta: + "description" -> { "CFE-3866" } + string => "Test that set_variable_values_ini does not error when promised key is not present"; + +} + +####################################################### + +bundle agent check +{ + + methods: + + "Pass/FAIL" + usebundle => dcs_passif_output(".*", ".*error.*", "$(sys.cf_agent) -Kf $(this.promise_filename).sub --define AUTO", $(this.promise_filename)); + +} diff --git a/tests/acceptance/lib/files/set_variable_values_ini_no_error_when_keys_in_section_not_present.cf.sub b/tests/acceptance/lib/files/set_variable_values_ini_no_error_when_keys_in_section_not_present.cf.sub new file mode 100644 index 000000000..0c291b0b7 --- /dev/null +++ b/tests/acceptance/lib/files/set_variable_values_ini_no_error_when_keys_in_section_not_present.cf.sub @@ -0,0 +1,70 @@ +####################################################### +# +# Test bundle set_config_values_ini +# +####################################################### + +body common control +{ + inputs => { '../../default.cf.sub' }; + bundlesequence => { default("$(this.promise_filename)") }; + version => "1.0"; +} + +####################################################### + +bundle agent init +{ + files: + + "$(G.testfile).actual" + copy_from => local_cp("$(this.promise_filename).start"); + + + "$(G.testfile).expected" + copy_from => local_cp("$(this.promise_filename).finish"); + +} + +####################################################### + +bundle agent test +{ + meta: + "description" -> { "CFE-3866" } + string => "Test that set_variable_values_ini does not error when promised key is not present"; + + vars: + "config[section 1][present_at_start]" string => "1"; + "config[section 1][absent_at_start]" string => "1"; + "config[section 2][present_at_start]" string => "two"; + "sections" slist => getindices( config ); + + files: + + "$(G.testfile).actual" + edit_line => set_variable_values_ini("test.config", "$(sections)"); + +} + +####################################################### + +bundle agent check +{ + + methods: + + "check" + usebundle => dcs_if_diff( "$(G.testfile).actual", "$(G.testfile).expected", + "pass", "_fail"); + + # Fail the test if any of the files fail. + "fail" + usebundle => dcs_fail( $(this.promise_filename) ), + if => "_fail"; + + pass:: + "pass" + usebundle => dcs_pass( $(this.promise_filename) ); + +} diff --git a/tests/acceptance/lib/files/set_variable_values_ini_no_error_when_keys_in_section_not_present.cf.sub.finish b/tests/acceptance/lib/files/set_variable_values_ini_no_error_when_keys_in_section_not_present.cf.sub.finish new file mode 100644 index 000000000..49c619c8f --- /dev/null +++ b/tests/acceptance/lib/files/set_variable_values_ini_no_error_when_keys_in_section_not_present.cf.sub.finish @@ -0,0 +1,5 @@ +[section 1] +present_at_start=1 +absent_at_start=1 +[section 2] +present_at_start=two diff --git a/tests/acceptance/lib/files/set_variable_values_ini_no_error_when_keys_in_section_not_present.cf.sub.start b/tests/acceptance/lib/files/set_variable_values_ini_no_error_when_keys_in_section_not_present.cf.sub.start new file mode 100644 index 000000000..f2fd73a17 --- /dev/null +++ b/tests/acceptance/lib/files/set_variable_values_ini_no_error_when_keys_in_section_not_present.cf.sub.start @@ -0,0 +1,4 @@ +[section 1] +present_at_start=1 +[section 2] +present_at_start=two