Skip to content

Commit

Permalink
RuleBasedEditor: misc. refactoring in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jouvin committed Apr 23, 2016
1 parent 40fbe2a commit 9f46650
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 138 deletions.
20 changes: 10 additions & 10 deletions src/test/perl/rbe_build_line_pattern.t
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");


Expand Down
33 changes: 14 additions & 19 deletions src/test/perl/rbe_remove_variable.t
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand Down
76 changes: 31 additions & 45 deletions src/test/perl/rbe_rule_parser.t
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -447,40 +439,36 @@ $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();

$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();

Expand All @@ -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();

Expand All @@ -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();

Expand Down
Loading

0 comments on commit 9f46650

Please sign in to comment.