diff options
| author | Paul Buetow <paul@buetow.org> | 2023-03-27 22:13:30 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-03-27 22:13:30 +0300 |
| commit | 54f506de1fd1d0f58fe0c50f88476df89241dd7e (patch) | |
| tree | c8c56dfca9c1c99a9ac7e28826712e7982feaab6 | |
| parent | 5da8d3b684e11b607de9461292cc1c83fdabdfdd (diff) | |
add unit tests
| -rw-r--r-- | fixtures/Host.Boots.expected-output | 11 | ||||
| -rw-r--r-- | fixtures/Host.Downtime.expected-output | 11 | ||||
| -rw-r--r-- | fixtures/Host.Lifespan.expected-output | 11 | ||||
| -rw-r--r-- | fixtures/Host.MetaScore.expected-output | 11 | ||||
| -rw-r--r-- | fixtures/Host.Uptime.expected-output | 11 | ||||
| -rw-r--r-- | fixtures/OS.Boots.expected-output | 11 | ||||
| -rw-r--r-- | fixtures/OS.MetaScore.expected-output | 11 | ||||
| -rw-r--r-- | fixtures/OS.Uptime.expected-output | 11 | ||||
| -rw-r--r-- | fixtures/OSMajor.Boots.expected-output | 11 | ||||
| -rw-r--r-- | fixtures/OSMajor.MetaScore.expected-output | 11 | ||||
| -rw-r--r-- | fixtures/OSMajor.Uptime.expected-output | 11 | ||||
| -rw-r--r-- | fixtures/Uname.Boots.expected-output | 10 | ||||
| -rw-r--r-- | fixtures/Uname.MetaScore.expected-output | 10 | ||||
| -rw-r--r-- | fixtures/Uname.Uptime.expected-output | 10 | ||||
| -rw-r--r-- | guprecords.raku | 52 |
15 files changed, 185 insertions, 18 deletions
diff --git a/fixtures/Host.Boots.expected-output b/fixtures/Host.Boots.expected-output new file mode 100644 index 0000000..46e4586 --- /dev/null +++ b/fixtures/Host.Boots.expected-output @@ -0,0 +1,11 @@ +Top 5 Boots's by Host: + ++-----+----------------+-------+ +| Pos | Host | Boots | ++-----+----------------+-------+ +| 1. | alphacentauri | 671 | +| 2. | mars | 207 | +| 3. | callisto | 153 | +| 4. | uranus | 150 | +| 5. | dionysus | 136 | ++-----+----------------+-------+ diff --git a/fixtures/Host.Downtime.expected-output b/fixtures/Host.Downtime.expected-output new file mode 100644 index 0000000..e3974c9 --- /dev/null +++ b/fixtures/Host.Downtime.expected-output @@ -0,0 +1,11 @@ +Top 5 Downtime's by Host: + ++-----+----------------+-----------------------------+ +| Pos | Host | Downtime | ++-----+----------------+-----------------------------+ +| 1. | dionysus | 8 years, 3 months, 16 days | +| 2. | alphacentauri | 5 years, 11 months, 18 days | +| 3. | uranus | 3 years, 3 months, 28 days | +| 4. | callisto | 1 years, 5 months, 15 days | +| 5. | mars | 1 years, 2 months, 10 days | ++-----+----------------+-----------------------------+ diff --git a/fixtures/Host.Lifespan.expected-output b/fixtures/Host.Lifespan.expected-output new file mode 100644 index 0000000..1bc40d4 --- /dev/null +++ b/fixtures/Host.Lifespan.expected-output @@ -0,0 +1,11 @@ +Top 5 Lifespan's by Host: + ++-----+----------------+----------------------------+ +| Pos | Host | Lifespan | ++-----+----------------+----------------------------+ +| 1. | dionysus | 8 years, 6 months, 17 days | +| 2. | uranus | 7 years, 2 months, 16 days | +| 3. | alphacentauri | 6 years, 9 months, 13 days | +| 4. | *vulcan | 4 years, 4 months, 7 days | +| 5. | sun | 3 years, 10 months, 2 days | ++-----+----------------+----------------------------+ diff --git a/fixtures/Host.MetaScore.expected-output b/fixtures/Host.MetaScore.expected-output new file mode 100644 index 0000000..457a5cf --- /dev/null +++ b/fixtures/Host.MetaScore.expected-output @@ -0,0 +1,11 @@ +Top 5 MetaScore's by Host: + ++-----+----------------+-----------+ +| Pos | Host | MetaScore | ++-----+----------------+-----------+ +| 1. | uranus | 360 | +| 2. | alphacentauri | 294 | +| 3. | dionysus | 285 | +| 4. | *vulcan | 273 | +| 5. | sun | 238 | ++-----+----------------+-----------+ diff --git a/fixtures/Host.Uptime.expected-output b/fixtures/Host.Uptime.expected-output new file mode 100644 index 0000000..3264e49 --- /dev/null +++ b/fixtures/Host.Uptime.expected-output @@ -0,0 +1,11 @@ +Top 5 Uptime's by Host: + ++-----+------------+-----------------------------+ +| Pos | Host | Uptime | ++-----+------------+-----------------------------+ +| 1. | *vulcan | 4 years, 4 months, 7 days | +| 2. | uranus | 3 years, 11 months, 21 days | +| 3. | sun | 3 years, 9 months, 26 days | +| 4. | uugrn | 3 years, 5 months, 5 days | +| 5. | deltavega | 3 years, 1 months, 21 days | ++-----+------------+-----------------------------+ diff --git a/fixtures/OS.Boots.expected-output b/fixtures/OS.Boots.expected-output new file mode 100644 index 0000000..d7cbe84 --- /dev/null +++ b/fixtures/OS.Boots.expected-output @@ -0,0 +1,11 @@ +Top 5 Boots's by OS: + ++-----+------------------------------+-------+ +| Pos | OS | Boots | ++-----+------------------------------+-------+ +| 1. | Linux 3.2.0-4-amd64 | 321 | +| 2. | Linux 4.0.4-303.fc22.x86_64 | 103 | +| 3. | FreeBSD 10.1-RELEASE | 76 | +| 4. | FreeBSD 10.0-RELEASE | 52 | +| 5. | FreeBSD 10.1-RELEASE-p19 | 48 | ++-----+------------------------------+-------+ diff --git a/fixtures/OS.MetaScore.expected-output b/fixtures/OS.MetaScore.expected-output new file mode 100644 index 0000000..59fdb15 --- /dev/null +++ b/fixtures/OS.MetaScore.expected-output @@ -0,0 +1,11 @@ +Top 5 MetaScore's by OS: + ++-----+------------------------------------+-----------+ +| Pos | OS | MetaScore | ++-----+------------------------------------+-----------+ +| 1. | Linux 3.2.0-4-amd64 | 241 | +| 2. | *Linux 3.10.0-1160.15.2.el7.x86_64 | 126 | +| 3. | Linux 3.10.0-957.21.3.el7.x86_64 | 96 | +| 4. | FreeBSD 10.1-RELEASE-p16 | 88 | +| 5. | FreeBSD 10.2-RELEASE | 75 | ++-----+------------------------------------+-----------+ diff --git a/fixtures/OS.Uptime.expected-output b/fixtures/OS.Uptime.expected-output new file mode 100644 index 0000000..680ed06 --- /dev/null +++ b/fixtures/OS.Uptime.expected-output @@ -0,0 +1,11 @@ +Top 5 Uptime's by OS: + ++-----+------------------------------------+-----------------------------+ +| Pos | OS | Uptime | ++-----+------------------------------------+-----------------------------+ +| 1. | Linux 3.2.0-4-amd64 | 3 years, 5 months, 23 days | +| 2. | *Linux 3.10.0-1160.15.2.el7.x86_64 | 1 years, 12 months, 15 days | +| 3. | Linux 3.10.0-957.21.3.el7.x86_64 | 1 years, 7 months, 13 days | +| 4. | FreeBSD 10.1-RELEASE-p16 | 1 years, 5 months, 23 days | +| 5. | FreeBSD 10.2-RELEASE | 1 years, 3 months, 11 days | ++-----+------------------------------------+-----------------------------+ diff --git a/fixtures/OSMajor.Boots.expected-output b/fixtures/OSMajor.Boots.expected-output new file mode 100644 index 0000000..e98f8e9 --- /dev/null +++ b/fixtures/OSMajor.Boots.expected-output @@ -0,0 +1,11 @@ +Top 5 Boots's by OSMajor: + ++-----+----------------+-------+ +| Pos | OSMajor | Boots | ++-----+----------------+-------+ +| 1. | FreeBSD 10... | 551 | +| 2. | *Linux 3... | 410 | +| 3. | Linux 5... | 249 | +| 4. | Linux 4... | 164 | +| 5. | FreeBSD 11... | 153 | ++-----+----------------+-------+ diff --git a/fixtures/OSMajor.MetaScore.expected-output b/fixtures/OSMajor.MetaScore.expected-output new file mode 100644 index 0000000..f04bbfe --- /dev/null +++ b/fixtures/OSMajor.MetaScore.expected-output @@ -0,0 +1,11 @@ +Top 5 MetaScore's by OSMajor: + ++-----+----------------+-----------+ +| Pos | OSMajor | MetaScore | ++-----+----------------+-----------+ +| 1. | *Linux 3... | 739 | +| 2. | FreeBSD 10... | 406 | +| 3. | Linux 5... | 268 | +| 4. | Linux 4... | 178 | +| 5. | *OpenBSD 7... | 159 | ++-----+----------------+-----------+ diff --git a/fixtures/OSMajor.Uptime.expected-output b/fixtures/OSMajor.Uptime.expected-output new file mode 100644 index 0000000..2a595ea --- /dev/null +++ b/fixtures/OSMajor.Uptime.expected-output @@ -0,0 +1,11 @@ +Top 5 Uptime's by OSMajor: + ++-----+----------------+-----------------------------+ +| Pos | OSMajor | Uptime | ++-----+----------------+-----------------------------+ +| 1. | *Linux 3... | 11 years, 2 months, 11 days | +| 2. | FreeBSD 10... | 5 years, 9 months, 9 days | +| 3. | Linux 5... | 3 years, 12 months, 2 days | +| 4. | Linux 4... | 2 years, 8 months, 9 days | +| 5. | *OpenBSD 7... | 2 years, 6 months, 9 days | ++-----+----------------+-----------------------------+ diff --git a/fixtures/Uname.Boots.expected-output b/fixtures/Uname.Boots.expected-output new file mode 100644 index 0000000..fb66c9d --- /dev/null +++ b/fixtures/Uname.Boots.expected-output @@ -0,0 +1,10 @@ +Top 5 Boots's by Uname: + ++-----+----------+-------+ +| Pos | Uname | Boots | ++-----+----------+-------+ +| 1. | *FreeBSD | 872 | +| 2. | *Linux | 867 | +| 3. | *OpenBSD | 44 | +| 4. | Darwin | 15 | ++-----+----------+-------+ diff --git a/fixtures/Uname.MetaScore.expected-output b/fixtures/Uname.MetaScore.expected-output new file mode 100644 index 0000000..6911238 --- /dev/null +++ b/fixtures/Uname.MetaScore.expected-output @@ -0,0 +1,10 @@ +Top 5 MetaScore's by Uname: + ++-----+----------+-----------+ +| Pos | Uname | MetaScore | ++-----+----------+-----------+ +| 1. | *Linux | 1295 | +| 2. | *FreeBSD | 703 | +| 3. | *OpenBSD | 198 | +| 4. | Darwin | 29 | ++-----+----------+-----------+ diff --git a/fixtures/Uname.Uptime.expected-output b/fixtures/Uname.Uptime.expected-output new file mode 100644 index 0000000..63aef68 --- /dev/null +++ b/fixtures/Uname.Uptime.expected-output @@ -0,0 +1,10 @@ +Top 5 Uptime's by Uname: + ++-----+----------+-----------------------------+ +| Pos | Uname | Uptime | ++-----+----------+-----------------------------+ +| 1. | *Linux | 19 years, 4 months, 18 days | +| 2. | *FreeBSD | 9 years, 11 months, 29 days | +| 3. | *OpenBSD | 3 years, 1 months, 18 days | +| 4. | Darwin | 0 years, 6 months, 15 days | ++-----+----------+-----------------------------+ diff --git a/guprecords.raku b/guprecords.raku index 37784fd..cb331ed 100644 --- a/guprecords.raku +++ b/guprecords.raku @@ -110,8 +110,9 @@ class Reporter { has Category $.category = Host; has Metric $.metric is required; - method report { - say "{self!output-header}Top {$.limit} {$.metric}'s by {$.category}:\n"; + method report returns Str { + my Str @ret; + push @ret, "{self!output-header}Top {$.limit} {$.metric}'s by {$.category}:\n\n"; with self!table -> (@table, %size) { my Str \format = '|' ~ join '|', @@ -119,18 +120,20 @@ class Reporter { my Str \border = '+' ~ join '+', '-' x (2+%size<count>), '-' x (2+%size<name>), '-' x (2+%size<value>), "\n"; - say self!output-block; - print border; - printf format, 'Pos', $.category, $.metric; - print border; + push @ret, self!output-block; + push @ret, border; + push @ret, sprintf format, 'Pos', $.category, $.metric; + push @ret, border; for @table -> \position, \name, \value { - printf format, position, name, value; + push @ret, sprintf format, position, name, value; } - print border; - say self!output-block; + push @ret, border; + push @ret, self!output-block; } + + return @ret.join(''); } method !table returns List { @@ -163,7 +166,7 @@ class Reporter { } method !output-block { - ($.output-format ~~ any (Markdown, Gemtext)) ?? '```' !! '' + ($.output-format ~~ any (Markdown, Gemtext)) ?? "```\n" !! '' } multi method sort-by(Uptime) { self.sort-by: *.uptime } @@ -197,9 +200,9 @@ multi sub MAIN( my Hash %aggregates = Aggregator.new($stats-dir).aggregate; if $category ~~ Host { - HostReporter.new(:%aggregates, :$metric, :$limit, :$output-format).report; + print HostReporter.new(:%aggregates, :$metric, :$limit, :$output-format).report; } elsif $metric ~~ MetricSubset { - Reporter.new(:%aggregates, :$category, :$metric, :$limit, :$output-format).report; + print Reporter.new(:%aggregates, :$category, :$metric, :$limit, :$output-format).report; } else { die "Category $category only supports the following metrics: {Metric.^enum_value_list.grep: * ~~ MetricSubset}"; } @@ -217,9 +220,9 @@ multi sub MAIN( for Category.^enum_value_list X Metric.^enum_value_list -> (Category $category, Metric $metric) { next if $category !~~ Host and $metric !~~ MetricSubset; if $category ~~ Host { - HostReporter.new(:%aggregates, :$metric, :$limit, :$output-format, :$header-indent).report + print HostReporter.new(:%aggregates, :$metric, :$limit, :$output-format, :$header-indent).report } else { - Reporter.new(:%aggregates, :$category, :$metric, :$limit, :$output-format, :$header-indent).report; + print Reporter.new(:%aggregates, :$category, :$metric, :$limit, :$output-format, :$header-indent).report; } say ''; } @@ -227,12 +230,25 @@ multi sub MAIN( multi sub MAIN('test') { use Test; - plan 1; - my Hash %aggregates = Aggregator.new('./fixtures').aggregate; + my @combs = gather { + for Category.^enum_value_list X Metric.^enum_value_list -> (Category $category, Metric $metric) { + next if $category !~~ Host and $metric !~~ MetricSubset; + take $category, $metric; + } + } - say %aggregates.raku; - #do-it('./fixtures', + plan @combs; + my $limit = 5; + my $output-format = Plaintext; + my %aggregates = Aggregator.new('./fixtures').aggregate; + + for @combs -> (Category $category, Metric $metric) { + my \reporter = $category ~~ Host + ?? HostReporter.new(:%aggregates, :$metric, :$limit, :$output-format) + !! Reporter.new(:%aggregates, :$category, :$metric, :$limit, :$output-format); + is reporter.report, "./fixtures/$category.$metric.expected-output".IO.slurp; + } done-testing; } |
