From 9f46650cdd26b533b4a818d3d3e372ed715f8916 Mon Sep 17 00:00:00 2001 From: Michel Jouvin Date: Sat, 23 Apr 2016 22:01:48 +0200 Subject: [PATCH] RuleBasedEditor: misc. refactoring in unit tests --- src/test/perl/rbe_build_line_pattern.t | 20 ++-- src/test/perl/rbe_remove_variable.t | 33 +++---- src/test/perl/rbe_rule_parser.t | 76 ++++++--------- src/test/perl/rbe_value_format.t | 128 ++++++++++++------------- 4 files changed, 119 insertions(+), 138 deletions(-) diff --git a/src/test/perl/rbe_build_line_pattern.t b/src/test/perl/rbe_build_line_pattern.t index 83b7ac23..50193078 100644 --- a/src/test/perl/rbe_build_line_pattern.t +++ b/src/test/perl/rbe_build_line_pattern.t @@ -55,10 +55,10 @@ Readonly my $KEYWORD => 'DPNS_HOST'; Readonly my $LINE_PATTERN_ENV_VAR => '#?\s*export DPNS_HOST='; Readonly my $LINE_PATTERN_KEY_VALUE => '#?\s*DPNS_HOST'; my $escaped_pattern = $fh->_buildLinePattern($KEYWORD, - LINE_FORMAT_ENV_VAR); + LINE_FORMAT_ENV_VAR); is($escaped_pattern, $LINE_PATTERN_ENV_VAR, "Environment variable pattern ok"); $escaped_pattern = $fh->_buildLinePattern($KEYWORD, - LINE_FORMAT_KEY_VAL); + LINE_FORMAT_KEY_VAL); is($escaped_pattern, $LINE_PATTERN_KEY_VALUE, "Key/value pattern ok"); # Build a line pattern without a parameter value @@ -73,20 +73,20 @@ Readonly my $EXPECTED_PATTERN_3 => '#?\s*export DPNS_HOST=\^dp\$n\-s\.\*ex\]\s+a Readonly my $VALUE_4 => 'a\b'; Readonly my $EXPECTED_PATTERN_4 => '#?\s*export DPNS_HOST=a\\\\b'; $escaped_pattern = $fh->_buildLinePattern($KEYWORD, - LINE_FORMAT_ENV_VAR, - $VALUE_1); + LINE_FORMAT_ENV_VAR, + $VALUE_1); is($escaped_pattern, $EXPECTED_PATTERN_1, "Environment variable with value (host name): pattern ok"); $escaped_pattern = $fh->_buildLinePattern($KEYWORD, - LINE_FORMAT_ENV_VAR, - $VALUE_2); + LINE_FORMAT_ENV_VAR, + $VALUE_2); is($escaped_pattern, $EXPECTED_PATTERN_2, "Environment variable with value (0): pattern ok"); $escaped_pattern = $fh->_buildLinePattern($KEYWORD, - LINE_FORMAT_ENV_VAR, - $VALUE_3); + LINE_FORMAT_ENV_VAR, + $VALUE_3); is($escaped_pattern, $EXPECTED_PATTERN_3, "Environment variable with value (special characters): pattern ok"); $escaped_pattern = $fh->_buildLinePattern($KEYWORD, - LINE_FORMAT_ENV_VAR, - $VALUE_4); + LINE_FORMAT_ENV_VAR, + $VALUE_4); is($escaped_pattern, $EXPECTED_PATTERN_4, "Environment variable with value (backslash): pattern ok"); diff --git a/src/test/perl/rbe_remove_variable.t b/src/test/perl/rbe_remove_variable.t index 7d9486e3..0d08af27 100644 --- a/src/test/perl/rbe_remove_variable.t +++ b/src/test/perl/rbe_remove_variable.t @@ -178,10 +178,9 @@ my $dpm_options = {}; set_file_contents($DPM_CONF_FILE,$DPM_INITIAL_CONF_1); my $fh = CAF::FileEditor->open($DPM_CONF_FILE, log => $this_app); ok(defined($fh), $DPM_CONF_FILE." was opened"); -$changes = $fh->updateFile( - \%config_rules_1, - $dpm_options, - \%parser_options); +$changes = $fh->updateFile(\%config_rules_1, + $dpm_options, + \%parser_options); is("$fh", $DPM_EXPECTED_CONF_1, $DPM_CONF_FILE." has expected contents (negated keywords)"); $fh->close(); @@ -190,10 +189,9 @@ $dpm_options = {"dpm" => {"globusThreadModel" => "pthread"}}; set_file_contents($DPM_CONF_FILE,$DPM_INITIAL_CONF_1); my $fh = CAF::FileEditor->open($DPM_CONF_FILE, log => $this_app); ok(defined($fh), $DPM_CONF_FILE." was opened"); -$changes = $fh->updateFile( - \%config_rules_2, - $dpm_options, - \%parser_options); +$changes = $fh->updateFile(\%config_rules_2, + $dpm_options, + \%parser_options); is("$fh", $DPM_EXPECTED_CONF_2, $DPM_CONF_FILE." has expected contents (config option not defined)"); $fh->close(); @@ -202,10 +200,9 @@ $dpm_options = {"dpm" => {"globusThreadModel" => "pthread"}}; set_file_contents($DPM_CONF_FILE,$DPM_INITIAL_CONF_1); my $fh = CAF::FileEditor->open($DPM_CONF_FILE, log => $this_app); ok(defined($fh), $DPM_CONF_FILE." was opened"); -$changes = $fh->updateFile( - \%config_rules_3, - $dpm_options, - \%parser_options); +$changes = $fh->updateFile(\%config_rules_3, + $dpm_options, + \%parser_options); is("$fh", $DPM_EXPECTED_CONF_1, $DPM_CONF_FILE." has expected contents (rule condition not met)"); $fh->close(); @@ -215,9 +212,8 @@ $dpm_options = {"dpm" => {"globusThreadModel" => "pthread"}}; set_file_contents($DPM_CONF_FILE,$DPM_INITIAL_CONF_1); my $fh = CAF::FileEditor->open($DPM_CONF_FILE, log => $this_app); ok(defined($fh), $DPM_CONF_FILE." was opened"); -$changes = $fh->updateFile( - \%config_rules_4, - $dpm_options); +$changes = $fh->updateFile(\%config_rules_4, + $dpm_options); is("$fh", $DPM_EXPECTED_CONF_2, $DPM_CONF_FILE." has expected contents (rule keyword prefixed by ?)"); $fh->close(); @@ -227,10 +223,9 @@ $dpm_options = {"dpm" => {"globusThreadModel" => "pthread"}}; set_file_contents($DPM_CONF_FILE,$DPM_INITIAL_CONF_2); my $fh = CAF::FileEditor->open($DPM_CONF_FILE, log => $this_app); ok(defined($fh), $DPM_CONF_FILE." was opened"); -$changes = $fh->updateFile( - \%config_rules_1, - $dpm_options, - \%parser_options); +$changes = $fh->updateFile(\%config_rules_1, + $dpm_options, + \%parser_options); is("$fh", $DPM_EXPECTED_CONF_3, $DPM_CONF_FILE." has expected contents (repeated config line)"); $fh->close(); diff --git a/src/test/perl/rbe_rule_parser.t b/src/test/perl/rbe_rule_parser.t index bc74c21f..94184c30 100644 --- a/src/test/perl/rbe_rule_parser.t +++ b/src/test/perl/rbe_rule_parser.t @@ -364,9 +364,8 @@ set_file_contents($DPM_CONF_FILE,$DPM_INITIAL_CONF_1); set_file_contents($DPM_CONF_FILE,$DPM_INITIAL_CONF_1); my $fh = CAF::FileEditor->open($DPM_CONF_FILE, log => $this_app); ok(defined($fh), $DPM_CONF_FILE." was opened"); -$changes = $fh->updateFile( - \%dpm_config_rules_1, - $dpm_options); +$changes = $fh->updateFile(\%dpm_config_rules_1, + $dpm_options); is("$fh", $DPM_EXPECTED_CONF_1, $DPM_CONF_FILE." has expected contents (config 1)"); $fh->close(); @@ -375,9 +374,8 @@ $fh->close(); set_file_contents($DPM_CONF_FILE,$DPM_INITIAL_CONF_2); my $fh = CAF::FileEditor->open($DPM_CONF_FILE, log => $this_app); ok(defined($fh), $DPM_CONF_FILE." was opened"); -$changes = $fh->updateFile( - \%dpm_config_rules_1, - $dpm_options); +$changes = $fh->updateFile(\%dpm_config_rules_1, + $dpm_options); is("$fh", $DPM_EXPECTED_CONF_2, $DPM_CONF_FILE." has expected contents (config 2)"); $fh->close(); @@ -386,9 +384,8 @@ $fh->close(); set_file_contents($DPM_CONF_FILE,$DPM_INITIAL_CONF_3); my $fh = CAF::FileEditor->open($DPM_CONF_FILE, log => $this_app); ok(defined($fh), $DPM_CONF_FILE." was opened"); -$changes = $fh->updateFile( - \%dpm_config_rules_2, - $dpm_options); +$changes = $fh->updateFile(\%dpm_config_rules_2, + $dpm_options); is("$fh", $DPM_EXPECTED_CONF_3, $DPM_CONF_FILE." has expected contents (config 3)"); $fh->close(); @@ -397,9 +394,8 @@ $fh->close(); set_file_contents($DMLITE_CONF_FILE,$DMLITE_INITIAL_CONF_1); my $fh = CAF::FileEditor->open($DMLITE_CONF_FILE, log => $this_app); ok(defined($fh), $DMLITE_CONF_FILE." was opened"); -$changes = $fh->updateFile( - \%dav_config_rules, - $dmlite_options); +$changes = $fh->updateFile(\%dav_config_rules, + $dmlite_options); is("$fh", $DMLITE_EXPECTED_CONF_1, $DMLITE_CONF_FILE." has expected contents"); $fh->close(); @@ -409,36 +405,32 @@ $fh->close(); set_file_contents($DMLITE_CONF_FILE,''); my $fh = CAF::FileEditor->open($DMLITE_CONF_FILE, log => $this_app); ok(defined($fh), $DMLITE_CONF_FILE." was opened"); -$changes = $fh->updateFile( - \%rules_with_conditions, - $all_options); +$changes = $fh->updateFile(\%rules_with_conditions, + $all_options); is("$fh", $COND_TEST_EXPECTED_1, $DMLITE_CONF_FILE." has expected contents (rules with conditions)"); $fh->close(); set_file_contents($DMLITE_CONF_FILE,''); my $fh = CAF::FileEditor->open($DMLITE_CONF_FILE, log => $this_app); ok(defined($fh), $DMLITE_CONF_FILE." was opened"); -$changes = $fh->updateFile( - \%rules_with_neg_conds, - $all_options); +$changes = $fh->updateFile(\%rules_with_neg_conds, + $all_options); is("$fh", $NEG_COND_TEST_EXPECTED_1, $DMLITE_CONF_FILE." has expected contents (rules with negative conditions)"); $fh->close(); set_file_contents($DMLITE_CONF_FILE,$COND_TEST_INITIAL); my $fh = CAF::FileEditor->open($DMLITE_CONF_FILE, log => $this_app); ok(defined($fh), $DMLITE_CONF_FILE." was opened"); -$changes = $fh->updateFile( - \%rules_with_conditions, - $all_options); +$changes = $fh->updateFile(\%rules_with_conditions, + $all_options); is("$fh", $COND_TEST_INITIAL, $DMLITE_CONF_FILE." has expected contents (initial contents, rules conditions with non existent attribute)"); $fh->close(); set_file_contents($DMLITE_CONF_FILE,$COND_TEST_INITIAL); my $fh = CAF::FileEditor->open($DMLITE_CONF_FILE, log => $this_app); ok(defined($fh), $DMLITE_CONF_FILE." was opened"); -$changes = $fh->updateFile( - \%rules_with_conditions_2, - $all_options); +$changes = $fh->updateFile(\%rules_with_conditions_2, + $all_options); is("$fh", $COND_TEST_INITIAL, $DMLITE_CONF_FILE." has expected contents (initial contents, rules conditions with non existent option set)"); $fh->close(); @@ -447,29 +439,26 @@ $parser_options{remove_if_undef} = 1; set_file_contents($DMLITE_CONF_FILE,$COND_TEST_INITIAL); my $fh = CAF::FileEditor->open($DMLITE_CONF_FILE, log => $this_app); ok(defined($fh), $DMLITE_CONF_FILE." was opened"); -$changes = $fh->updateFile( - \%rules_with_conditions, - $all_options, - \%parser_options); +$changes = $fh->updateFile(\%rules_with_conditions, + $all_options, + \%parser_options); is("$fh", $COND_TEST_EXPECTED_2, $DMLITE_CONF_FILE." has expected contents (initial contents, rules conditions, parser options)"); $fh->close(); set_file_contents($DMLITE_CONF_FILE,$COND_TEST_INITIAL); my $fh = CAF::FileEditor->open($DMLITE_CONF_FILE, log => $this_app); ok(defined($fh), $DMLITE_CONF_FILE." was opened"); -$changes = $fh->updateFile( - \%rules_with_neg_conds, - $all_options, - \%parser_options); +$changes = $fh->updateFile(\%rules_with_neg_conds, + $all_options, + \%parser_options); is("$fh", $NEG_COND_TEST_EXPECTED_2, $DMLITE_CONF_FILE." has expected contents (initial contents, rules with negative conditions, parser options)"); $fh->close(); set_file_contents($DMLITE_CONF_FILE,''); my $fh = CAF::FileEditor->open($DMLITE_CONF_FILE, log => $this_app); ok(defined($fh), $DMLITE_CONF_FILE." was opened"); -$changes = $fh->updateFile( - \%rules_always, - $dmlite_options); +$changes = $fh->updateFile(\%rules_always, + $dmlite_options); is("$fh", $COND_TEST_EXPECTED_3, $DMLITE_CONF_FILE." has expected contents (always_rules_only not set)"); $fh->close(); @@ -477,10 +466,9 @@ $parser_options{always_rules_only} = 1; set_file_contents($DMLITE_CONF_FILE,''); my $fh = CAF::FileEditor->open($DMLITE_CONF_FILE, log => $this_app); ok(defined($fh), $DMLITE_CONF_FILE." was opened"); -$changes = $fh->updateFile( - \%rules_always, - $dmlite_options, - \%parser_options); +$changes = $fh->updateFile(\%rules_always, + $dmlite_options, + \%parser_options); is("$fh", $COND_TEST_EXPECTED_1, $DMLITE_CONF_FILE." has expected contents (always_rules_only set)"); $fh->close(); @@ -489,9 +477,8 @@ $fh->close(); set_file_contents($DPM_SHIFT_CONF_FILE,''); my $fh = CAF::FileEditor->open($DPM_SHIFT_CONF_FILE, log => $this_app); ok(defined($fh), $DPM_SHIFT_CONF_FILE." was opened"); -$changes = $fh->updateFile( - \%rules_no_rule, - $dpm_options); +$changes = $fh->updateFile(\%rules_no_rule, + $dpm_options); is("$fh", $NO_RULE_EXPECTED, $DPM_SHIFT_CONF_FILE." has expected contents (keyword only)"); $fh->close(); @@ -500,9 +487,8 @@ $fh->close(); set_file_contents($DPM_SHIFT_CONF_FILE,''); my $fh = CAF::FileEditor->open($DPM_SHIFT_CONF_FILE, log => $this_app); ok(defined($fh), $DPM_SHIFT_CONF_FILE." was opened"); -$changes = $fh->updateFile( - \%rules_multi_cond_sets, - $dpm_options); +$changes = $fh->updateFile(\%rules_multi_cond_sets, + $dpm_options); is("$fh", $MULTI_COND_SETS_EXPECTED, $DPM_SHIFT_CONF_FILE." has expected contents (multiple condition sets)"); $fh->close(); diff --git a/src/test/perl/rbe_value_format.t b/src/test/perl/rbe_value_format.t index 73668cfa..d7079592 100644 --- a/src/test/perl/rbe_value_format.t +++ b/src/test/perl/rbe_value_format.t @@ -55,22 +55,22 @@ Readonly my $FALSE => 'no'; Readonly my $TRUE => 'yes'; Readonly my $TRUE_QUOTED => '"yes"'; $formatted_value = $rbe_fh->_formatAttributeValue(0, - LINE_FORMAT_KEY_VAL, - LINE_VALUE_BOOLEAN, - 0, - ); + LINE_FORMAT_KEY_VAL, + LINE_VALUE_BOOLEAN, + 0, + ); is($formatted_value, $FALSE, "Boolean (false) correctly formatted"); $formatted_value = $rbe_fh->_formatAttributeValue(1, - LINE_FORMAT_KEY_VAL, - LINE_VALUE_BOOLEAN, - 0, - ); + LINE_FORMAT_KEY_VAL, + LINE_VALUE_BOOLEAN, + 0, + ); is($formatted_value, $TRUE, "Boolean (true) correctly formatted"); $formatted_value = $rbe_fh->_formatAttributeValue(1, - LINE_FORMAT_SH_VAR, - LINE_VALUE_BOOLEAN, - 0, - ); + LINE_FORMAT_SH_VAR, + LINE_VALUE_BOOLEAN, + 0, + ); is($formatted_value, $TRUE_QUOTED, "Boolean (true, quoted) correctly formatted"); @@ -81,46 +81,46 @@ Readonly my $AS_IS_VALUE_SINGLE_QUOTED => "'This is a Test'"; Readonly my $EMPTY_VALUE => ''; Readonly my $EMPTY_VALUE_QUOTED => '""'; $formatted_value = $rbe_fh->_formatAttributeValue($AS_IS_VALUE, - LINE_FORMAT_KEY_VAL, - LINE_VALUE_AS_IS, - 0, - ); + LINE_FORMAT_KEY_VAL, + LINE_VALUE_AS_IS, + 0, + ); is($formatted_value, $AS_IS_VALUE, "Literal value correctly formatted"); $formatted_value = $rbe_fh->_formatAttributeValue($AS_IS_VALUE, - LINE_FORMAT_ENV_VAR, - LINE_VALUE_AS_IS, - 0, - ); + LINE_FORMAT_ENV_VAR, + LINE_VALUE_AS_IS, + 0, + ); is($formatted_value, $AS_IS_VALUE_DOUBLE_QUOTED, "Literal value (quoted) correctly formatted"); $formatted_value = $rbe_fh->_formatAttributeValue($AS_IS_VALUE_DOUBLE_QUOTED, - LINE_FORMAT_KEY_VAL, - LINE_VALUE_AS_IS, - 0, - ); + LINE_FORMAT_KEY_VAL, + LINE_VALUE_AS_IS, + 0, + ); is($formatted_value, $AS_IS_VALUE_DOUBLE_QUOTED, "Quoted literal value correctly formatted"); $formatted_value = $rbe_fh->_formatAttributeValue($AS_IS_VALUE_DOUBLE_QUOTED, - LINE_FORMAT_ENV_VAR, - LINE_VALUE_AS_IS, - 0, - ); + LINE_FORMAT_ENV_VAR, + LINE_VALUE_AS_IS, + 0, + ); is($formatted_value, $AS_IS_VALUE_DOUBLE_QUOTED, "Already quoted literal value correctly formatted"); $formatted_value = $rbe_fh->_formatAttributeValue($AS_IS_VALUE_SINGLE_QUOTED, - LINE_FORMAT_ENV_VAR, - LINE_VALUE_AS_IS, - 0, - ); + LINE_FORMAT_ENV_VAR, + LINE_VALUE_AS_IS, + 0, + ); is($formatted_value, $AS_IS_VALUE_SINGLE_QUOTED, "Already single quoted literal value correctly formatted"); $formatted_value = $rbe_fh->_formatAttributeValue($EMPTY_VALUE, - LINE_FORMAT_KEY_VAL, - LINE_VALUE_AS_IS, - 0, - ); + LINE_FORMAT_KEY_VAL, + LINE_VALUE_AS_IS, + 0, + ); is($formatted_value, $EMPTY_VALUE, "Empty value correctly formatted"); $formatted_value = $rbe_fh->_formatAttributeValue($EMPTY_VALUE, - LINE_FORMAT_SH_VAR, - LINE_VALUE_AS_IS, - 0, - ); + LINE_FORMAT_SH_VAR, + LINE_VALUE_AS_IS, + 0, + ); is($formatted_value, $EMPTY_VALUE_QUOTED, "Empty value (quoted) correctly formatted"); @@ -134,16 +134,16 @@ Readonly my %INSTANCE_PARAMS => (logFile => '/test/instance.log', Readonly my $FORMATTED_INSTANCE_PARAMS => ' -l /test/instance.log -k 60'; Readonly my $FORMATTED_INSTANCE_PARAMS_QUOTED => '" -l /test/instance.log -k 60"'; $formatted_value = $rbe_fh->_formatAttributeValue(\%INSTANCE_PARAMS, - LINE_FORMAT_KEY_VAL, - LINE_VALUE_INSTANCE_PARAMS, - 0, - ); + LINE_FORMAT_KEY_VAL, + LINE_VALUE_INSTANCE_PARAMS, + 0, + ); is($formatted_value, $FORMATTED_INSTANCE_PARAMS, "Instance params correctly formatted"); $formatted_value = $rbe_fh->_formatAttributeValue(\%INSTANCE_PARAMS, - LINE_FORMAT_SH_VAR, - LINE_VALUE_INSTANCE_PARAMS, - 0, - ); + LINE_FORMAT_SH_VAR, + LINE_VALUE_INSTANCE_PARAMS, + 0, + ); is($formatted_value, $FORMATTED_INSTANCE_PARAMS_QUOTED, "Instance params (quoted) correctly formatted"); @@ -155,31 +155,31 @@ Readonly my $FORMATTED_ARRAY_UNIQUE => 'confFile logFile logKeep unused'; my $rbe_fh = CAF::FileEditor->open($FILENAME, log => $this_app); ok(defined($rbe_fh), $FILENAME." was opened"); $formatted_value = $rbe_fh->_formatAttributeValue(\@TEST_ARRAY, - LINE_FORMAT_KEY_VAL, - LINE_VALUE_ARRAY, - 0, - ); + LINE_FORMAT_KEY_VAL, + LINE_VALUE_ARRAY, + 0, + ); is($formatted_value, $FORMATTED_ARRAY, "Array values correctly formatted"); $formatted_value = $rbe_fh->_formatAttributeValue(\@TEST_ARRAY, - LINE_FORMAT_KEY_VAL, - LINE_VALUE_ARRAY, - LINE_VALUE_OPT_SORTED, - ); + LINE_FORMAT_KEY_VAL, + LINE_VALUE_ARRAY, + LINE_VALUE_OPT_SORTED, + ); is($formatted_value, $FORMATTED_ARRAY_SORTED, "Array values (sorted) correctly formatted"); $formatted_value = $rbe_fh->_formatAttributeValue(\@TEST_ARRAY, - LINE_FORMAT_KEY_VAL, - LINE_VALUE_ARRAY, - LINE_VALUE_OPT_UNIQUE, - ); + LINE_FORMAT_KEY_VAL, + LINE_VALUE_ARRAY, + LINE_VALUE_OPT_UNIQUE, + ); is($formatted_value, $FORMATTED_ARRAY_UNIQUE, "Array values (unique) correctly formatted"); # LINE_VALUE_HASH_KEYS $formatted_value = $rbe_fh->_formatAttributeValue(\%INSTANCE_PARAMS, - LINE_FORMAT_KEY_VAL, - LINE_VALUE_HASH_KEYS, - 0, - ); + LINE_FORMAT_KEY_VAL, + LINE_VALUE_HASH_KEYS, + 0, + ); is($formatted_value, $FORMATTED_ARRAY_UNIQUE, "Hash keys correctly formatted");