Debian Codegraph @

t/04_advanced.t

raw symbols SCIP
1 use Test::Simple tests => 12;
2
3 my $GCPLOG = 't/fixtures/cloudsql.log.gz';
4 my $SYSLOG1 = 't/fixtures/pg-syslog.1.bz2';
5 my $SYSLOG2 = 't/fixtures/pg-syslog.1.bz2';
6 my $STDERR1 = 't/fixtures/postgresql_param_range.log';
7 my $STDERR2 = 't/fixtures/multiline_param.log';
8 my $RAWCSV = 't/fixtures/pg_rawcsv.log';
9 my $JSON = 't/out.json';
10 my $TEXT = 't/out.txt';
11
12 `rm t/cluster1_day_*.bin t/file_cluster1 2>/dev/null`;
13 `rm *.html 2>/dev/null`;
14 my $ret = `perl pgbadger -q --exclude-db=pgbench --explode $SYSLOG1 && ls *.html`;
15 chomp($ret);
16 ok( $? == 0 && ($ret eq "out.html"), "Test --exclude-db + --explode");
17
18 $ret = `perl pgbadger -q --dbname=pgbench --explode $SYSLOG1 && ls *.html`;
19 chomp($ret);
20 ok( $? == 0 && ($ret eq "pgbench_out.html"), "Test --dbname + --explode");
21
22 `rm *.html`;
23
24 my $incr_outdir = "/tmp/pgbadger_data_tmp";
25 mkdir($incr_outdir);
26
27 $ret = `perl pgbadger -q --explode -I -O $incr_outdir $SYSLOG1 $SYSLOG2 && ls $incr_outdir | wc -l`;
28 chomp($ret);
29 ok( $? == 0 && ($ret == 4), "Test incremental mode with --explode");
30
31 `rm -rf $incr_outdir/*`;
32
33 $ret = `perl pgbadger -q --dbname=pgbench --explode -I -O $incr_outdir $SYSLOG1 $SYSLOG2 && ls $incr_outdir | grep ">12,474 queries" $incr_outdir/pgbench/20*/week-0*/index.html`;
34 chomp($ret);
35 ok( $? == 0 && ($ret ne ''), "Test incremental mode with --explode and --dbname");
36
37 $ret = `perl pgbadger -q --exclude-db cloudsqladmin --explode $GCPLOG && ls *.html | wc -l`;
38 chomp($ret);
39 ok( $? == 0 && ($ret == 2), "Test database exclusion with jsonlog");
40
41 $ret = `perl pgbadger --disable-type --disable-session --disable-connection --disable-lock --disable-checkpoint --disable-autovacuum --disable-query -o $TEXT t/fixtures/tempfile_only.log.gz -q`;
42 $ret = `grep "Example.*SELECT" $TEXT | wc -l`;
43 chomp($ret);
44 ok( $? == 0 && ($ret == 9), "Test log_temp_files only");
45
46 $ret = `perl pgbadger --last-parsed t/file_cluster1 -o t/cluster1_day_1.bin t/fixtures/tempfile_only.log.gz -q`;
47 $ret = `md5sum t/file_cluster1 | awk '{print \$1}'`;
48 chomp($ret);
49 ok( $? == 0 && ($ret eq "7faeb101abf32de3bc4e14fcf525e005" ), "Test last parse file without incremental mode");
50
51 $ret = `perl pgbadger --last-parsed t/file_cluster1 -o t/cluster1_day_2.bin t/fixtures/tempfile_only.log.gz -q`;
52 $ret = `ls -la t/cluster1_day_2.bin | awk '{print \$4}'`;
53 chomp($ret);
54 ok( $? == 0 && ($ret < 4000), "Second pass on last parse file without incremental mode");
55 $ret = `md5sum t/file_cluster1 | awk '{print \$1}'`;
56 chomp($ret);
57 ok( $? == 0 && ($ret eq "7faeb101abf32de3bc4e14fcf525e005" ), "Last parse file must not have changed");
58
59 `rm -f $JSON 2>/dev/null`;
60 $ret = `perl pgbadger -f stderr -q $STDERR1 -o $JSON`;
61 $ret = `grep "('D17756227', 'J16274127', 'IDA001127') and (public.t_plage_cloturee_utilisateur.pcu_range_cloture && '\\[2023-02-24T00:00,2023-02-25T00:00\\]'::tsrange" $JSON | wc -l`;
62 chomp($ret);
63 ok( $? == 0 && ($ret == 1), "Bind parameter with range: $ret");
64
65 $ret = `perl pgbadger -q -o t/out.txt $STDERR2`;
66 $ret = `grep 'njvarchar\\\\nbye'* $TEXT | wc -l`;
67 chomp($ret);
68 ok( $? == 0 && ($ret == 4), "Multiline bind parameters: $ret");
69
70 $ret = `perl pgbadger -q -p '%m [%p] %q%u@%d ' --dump-raw-csv $RAWCSV`;
71 ok( $? == 0 && length($ret) == 638, "Dump log as raw csv: " . length($ret));
72
73 # Remove files generated during the tests
74 `rm -f *.html`;
75 `rm -f $TEXT`;
76 `rm -f $JSON`;
77 `rm -rf $incr_outdir`;
78 `rm t/cluster1_day_*.bin t/file_cluster1`;
79