]> git.proxmox.com Git - pve-cluster.git/blob - data/test/corosync_parser_test.pl
18ee4f7b2630d8e7631878d0f02802449b6f982f
[pve-cluster.git] / data / test / corosync_parser_test.pl
1 #!/usr/bin/perl
2
3 use lib '..';
4
5 use strict;
6 use warnings;
7
8 use Test::More;
9
10 use PVE::Corosync;
11
12 sub parser_self_check {
13 my $cfg_fn = shift;
14
15 my $outfile = "$cfg_fn.write";
16 my ($config1, $config2, $raw1, $raw2);
17
18 eval {
19 # read first time
20 $raw1 = PVE::Tools::file_get_contents($cfg_fn);
21 $config1 = PVE::Corosync::parse_conf($cfg_fn, $raw1);
22
23 # write config
24 $raw2 = PVE::Corosync::write_conf(undef, $config1);
25 # do not actually write cfg, but you can outcomment to do so, e.g. if
26 # you want to use diff for easy comparision
27 #PVE::Tools::file_set_contents($outfile, $raw2);
28
29 # reparse written config (must be the same as config1)
30 $config2 = PVE::Corosync::parse_conf(undef, $raw2);
31 }; warn $@ if $@;
32
33 # do not care for whitespace differences
34 delete $config1->{digest};
35 delete $config2->{digest};
36
37 is_deeply($config1, $config2, "self check hash: $cfg_fn");
38
39 # do not care about extra new lines
40 $raw1 =~ s/^\s*\n+//mg;
41 $raw2 =~ s/^\s*\n+//mg;
42
43 is($raw1, $raw2, "self check raw: $cfg_fn");
44 }
45
46 # exec tests
47 if (my $file = shift) {
48 parser_self_check($file);
49 } else {
50 foreach my $file (<corosync_configs/*.conf>) {
51 parser_self_check($file);
52 }
53 }
54
55 done_testing();