-
Notifications
You must be signed in to change notification settings - Fork 4
/
metric_test.ts
58 lines (49 loc) · 1.23 KB
/
metric_test.ts
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
import {
assert,
assertEquals,
assertThrows,
MetricMock,
test,
} from "./test_deps.ts";
import { isValidLabelName } from "./metric.ts";
test({
name: "isValidLabelName",
fn() {
const validNames = [
"valid_label_name",
"VALID_LABEL_NAME",
"_valid_label_name_",
"valid_label_name_2",
];
for (const name of validNames) {
assert(isValidLabelName(name));
}
const invalidNames = [
"",
"0_invalid_metric_name",
"$@#!",
];
for (const name of invalidNames) {
assert(!isValidLabelName(name));
}
},
});
test({
name: "Metric",
fn() {
const labelNames = ["label1", "label2"];
const invalidLabelNames = ["", ""];
const labelValues = ["value1", "value2"];
assertThrows(() => {
new MetricMock(labelNames);
});
assertThrows(() => {
new MetricMock(invalidLabelNames, labelValues);
});
const metricWithoutLabel = new MetricMock();
assertEquals(metricWithoutLabel.getLabelsAsString(), "");
const metricWithLabel = new MetricMock(labelNames, labelValues);
const expectedLabesAsString = '{label1="value1",label2="value2"}';
assertEquals(metricWithLabel.getLabelsAsString(), expectedLabesAsString);
},
});