-
Notifications
You must be signed in to change notification settings - Fork 1
/
GaugeStorageTesting.php
81 lines (66 loc) · 2.26 KB
/
GaugeStorageTesting.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
declare(strict_types=1);
namespace Zlodes\PrometheusClient\Storage\Testing;
use Zlodes\PrometheusClient\Storage\Commands\UpdateGauge;
use Zlodes\PrometheusClient\Storage\Contracts\GaugeStorage;
use Zlodes\PrometheusClient\Storage\DTO\MetricNameWithLabels;
use Zlodes\PrometheusClient\Storage\DTO\MetricValue;
// phpcs:ignore
use function PHPUnit\Framework\assertCount;
use function PHPUnit\Framework\assertEmpty;
use function PHPUnit\Framework\assertEquals;
use function PHPUnit\Framework\assertSame;
/**
* @codeCoverageIgnore
*/
trait GaugeStorageTesting
{
public function testFullCycle(): void
{
$storage = $this->createStorage();
assertEmpty([...$storage->fetchGauges()]);
// Set Bob to 36.6
$storage->updateGauge(
new UpdateGauge(
new MetricNameWithLabels('temperature', ['name' => 'Bob']),
36.6
),
);
// Set Alice by 36.8
$storage->updateGauge(
new UpdateGauge(
new MetricNameWithLabels('temperature', ['name' => 'Alice']),
36.8
),
);
// Set Alice by 36.5
$storage->updateGauge(
new UpdateGauge(
new MetricNameWithLabels('temperature', ['name' => 'Alice']),
36.5
),
);
// Set Bob to 37.5
$storage->updateGauge(
new UpdateGauge(
new MetricNameWithLabels('temperature', ['name' => 'Bob']),
37.5
),
);
/** @var MetricValue $gauges */
$gauges = [...$storage->fetchGauges()];
assertCount(2, $gauges);
// Bob
assertSame('temperature', $gauges[0]->metricNameWithLabels->metricName);
assertSame(['name' => 'Bob'], $gauges[0]->metricNameWithLabels->labels);
assertEquals(37.5, $gauges[0]->value);
// Alice
assertSame('temperature', $gauges[1]->metricNameWithLabels->metricName);
assertSame(['name' => 'Alice'], $gauges[1]->metricNameWithLabels->labels);
assertEquals(36.5, $gauges[1]->value);
// Clean
$storage->clearGauges();
assertEmpty([...$storage->fetchGauges()]);
}
abstract protected function createStorage(): GaugeStorage;
}