master
go 69 lines 1.74 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package metrix
4
5 import "testing"
6
7 func TestRegisterInstrumentValidationScenarios(t *testing.T) {
8 tests := map[string]struct {
9 run func(t *testing.T)
10 }{
11 "summary quantiles on gauge panic": {
12 run: func(t *testing.T) {
13 s := NewCollectorStore()
14 expectPanic(t, func() {
15 _ = s.Write().SnapshotMeter("svc").Gauge("load", WithSummaryQuantiles(0.5))
16 })
17 },
18 },
19 "histogram bounds on summary panic": {
20 run: func(t *testing.T) {
21 s := NewCollectorStore()
22 expectPanic(t, func() {
23 _ = s.Write().SnapshotMeter("svc").Summary("latency", WithHistogramBounds(1))
24 })
25 },
26 },
27 "stateset options on non-stateset panic": {
28 run: func(t *testing.T) {
29 s := NewCollectorStore()
30 expectPanic(t, func() {
31 _ = s.Write().SnapshotMeter("svc").Counter("requests_total", WithStateSetStates("up", "down"))
32 })
33 },
34 },
35 "window option on stateful gauge panic": {
36 run: func(t *testing.T) {
37 s := NewCollectorStore()
38 expectPanic(t, func() {
39 _ = s.Write().StatefulMeter("svc").Gauge("heap", WithWindow(WindowCycle))
40 })
41 },
42 },
43 "snapshot gauge freshness committed panic": {
44 run: func(t *testing.T) {
45 s := NewCollectorStore()
46 expectPanic(t, func() {
47 _ = s.Write().SnapshotMeter("svc").Gauge("load", WithFreshness(FreshnessCommitted))
48 })
49 },
50 },
51 "window cycle with explicit freshness committed panic": {
52 run: func(t *testing.T) {
53 s := NewCollectorStore()
54 expectPanic(t, func() {
55 _ = s.Write().StatefulMeter("svc").Summary(
56 "latency",
57 WithSummaryQuantiles(0.5),
58 WithWindow(WindowCycle),
59 WithFreshness(FreshnessCommitted),
60 )
61 })
62 },
63 },
64 }
65
66 for name, tc := range tests {
67 t.Run(name, tc.run)
68 }
69 }