-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcounter_test.ts
51 lines (41 loc) · 1.27 KB
/
counter_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
import { assertEquals, assertThrows, test } from "./test_deps.ts";
import { Counter } from "./counter.ts";
test({
name: "Counter",
fn() {
const counter1 = Counter.with({
name: "counter_without_labels",
help: "help",
});
assertEquals(counter1.description, "counter_without_labels");
assertEquals(counter1.expose(), undefined);
assertEquals(counter1.value(), undefined);
counter1.inc();
assertEquals(counter1.expose(), "counter_without_labels 1");
counter1.inc(42);
assertEquals(counter1.expose(), "counter_without_labels 43");
assertThrows(() => {
Counter.with({
name: "counter_without_labels",
help: "help",
labels: [],
});
});
const counter2 = Counter.with({
name: "counter_with_labels",
help: "help",
labels: ["label1", "label2"],
});
assertEquals(counter2.description, "counter_with_labels");
assertEquals(counter2.expose(), undefined);
assertEquals(counter2.value(), undefined);
assertThrows(() => {
counter2.inc(-1);
});
const counterLabel1 = counter2.labels({ label1: "value1" });
counterLabel1.inc();
assertEquals(counterLabel1.value(), 1);
counterLabel1.inc(42);
assertEquals(counterLabel1.value(), 43);
},
});