-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathmetrics_params_test.go
More file actions
83 lines (71 loc) · 2.07 KB
/
metrics_params_test.go
File metadata and controls
83 lines (71 loc) · 2.07 KB
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
82
83
/*
Copyright © 2025 Acronis International GmbH.
Released under MIT license.
*/
package middleware
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMetricsParams_SetValue(t *testing.T) {
tests := []struct {
name string
values map[string]string
addName string
addValue string
expectedValues map[string]string
}{
{
name: "add label to empty params",
values: nil,
addName: "service",
addValue: "api",
expectedValues: map[string]string{"service": "api"},
},
{
name: "add label to existing params",
values: map[string]string{"env": "prod"},
addName: "service",
addValue: "api",
expectedValues: map[string]string{"env": "prod", "service": "api"},
},
{
name: "overwrite existing label",
values: map[string]string{"service": "old"},
addName: "service",
addValue: "new",
expectedValues: map[string]string{"service": "new"},
},
{
name: "add empty value",
values: nil,
addName: "service",
addValue: "",
expectedValues: map[string]string{"service": ""},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
mp := &MetricsParams{values: tt.values}
mp.SetValue(tt.addName, tt.addValue)
assert.Equal(t, tt.expectedValues, mp.values)
})
}
}
func TestMetricsParams_MultipleOperations(t *testing.T) {
mp := &MetricsParams{}
// Initially empty
assert.Nil(t, mp.values)
// Add first label
mp.SetValue("service", "api")
assert.Equal(t, map[string]string{"service": "api"}, mp.values)
// Add second label
mp.SetValue("env", "prod")
assert.Equal(t, map[string]string{"service": "api", "env": "prod"}, mp.values)
// Add third label
mp.SetValue("version", "1.0")
assert.Equal(t, map[string]string{"service": "api", "env": "prod", "version": "1.0"}, mp.values)
// Overwrite existing label
mp.SetValue("env", "staging")
assert.Equal(t, map[string]string{"service": "api", "env": "staging", "version": "1.0"}, mp.values)
}