@@ -23,28 +23,24 @@ package metric_descriptions
23
23
24
24
import (
25
25
"testing"
26
- {{- if .global }}
27
26
28
27
"github.com/stretchr/testify/require"
29
- {{- end }}
30
28
)
31
29
32
30
func Test_{{ .ename }}_Descriptor(t *testing.T) {
33
31
{{ .ename }}()
34
32
}
35
33
36
- {{- if .global }}
37
-
38
- func Test_{{ .ename }}_Global(t *testing.T) {
39
- global := Get{{ .ename }}Factory()
34
+ func Test_{{ .ename }}_Factory(t *testing.T) {
35
+ global := New{{ .ename }}{{ .type }}Factory()
40
36
41
- object1 := {{ .ename }}Item {
37
+ object1 := {{ .ename }}Input {
42
38
{{- range $i, $field := .mapKeys }}
43
39
{{ $field }}: "1",
44
40
{{- end }}
45
41
}
46
42
47
- object2 := {{ .ename }}Item {
43
+ object2 := {{ .ename }}Input {
48
44
{{- range $i, $field := .mapKeys }}
49
45
{{ $field }}: "2",
50
46
{{- end }}
@@ -60,7 +56,7 @@ func Test_{{ .ename }}_Global(t *testing.T) {
60
56
})
61
57
62
58
t.Run("Add", func(t *testing.T) {
63
- global.Add(10, object1 )
59
+ global.Add(object1, 10 )
64
60
65
61
require.EqualValues(t, 10, global.Get(object1))
66
62
require.EqualValues(t, 0, global.Get(object2))
@@ -71,7 +67,7 @@ func Test_{{ .ename }}_Global(t *testing.T) {
71
67
})
72
68
73
69
t.Run("Add", func(t *testing.T) {
74
- global.Add(3, object2 )
70
+ global.Add(object2, 3 )
75
71
76
72
require.EqualValues(t, 10, global.Get(object1))
77
73
require.EqualValues(t, 3, global.Get(object2))
@@ -82,7 +78,7 @@ func Test_{{ .ename }}_Global(t *testing.T) {
82
78
})
83
79
84
80
t.Run("Dec", func(t *testing.T) {
85
- global.Add(-1, object1 )
81
+ global.Add(object1, -1 )
86
82
87
83
require.EqualValues(t, 9, global.Get(object1))
88
84
require.EqualValues(t, 3, global.Get(object2))
@@ -127,16 +123,16 @@ func Test_{{ .ename }}_Global(t *testing.T) {
127
123
}
128
124
{{- if eq .type "Counter" }}
129
125
130
- func Test_{{ .ename }}_Global_Counter (t *testing.T) {
131
- global := Get {{ .ename }}Factory()
126
+ func Test_{{ .ename }}_Factory_Counter (t *testing.T) {
127
+ global := New {{ .ename }}{{ .type }}Factory()
132
128
133
- object1 := {{ .ename }}Item {
129
+ object1 := {{ .ename }}Input {
134
130
{{- range $i, $field := .mapKeys }}
135
131
{{ $field }}: "1",
136
132
{{- end }}
137
133
}
138
134
139
- object2 := {{ .ename }}Item {
135
+ object2 := {{ .ename }}Input {
140
136
{{- range $i, $field := .mapKeys }}
141
137
{{ $field }}: "2",
142
138
{{- end }}
@@ -152,7 +148,7 @@ func Test_{{ .ename }}_Global_Counter(t *testing.T) {
152
148
})
153
149
154
150
t.Run("Add", func(t *testing.T) {
155
- global.Add(10, object1 )
151
+ global.Add(object1, 10 )
156
152
157
153
require.EqualValues(t, 10, global.Get(object1))
158
154
require.EqualValues(t, 0, global.Get(object2))
@@ -175,5 +171,54 @@ func Test_{{ .ename }}_Global_Counter(t *testing.T) {
175
171
})
176
172
}
177
173
{{- end }}
174
+ {{- if eq .type "Gauge" }}
175
+
176
+ func Test_{{ .ename }}_Factory_Gauge(t *testing.T) {
177
+ global := New{{ .ename }}{{ .type }}Factory()
178
178
179
+ object1 := {{ .ename }}Input{
180
+ {{- range $i, $field := .mapKeys }}
181
+ {{ $field }}: "1",
179
182
{{- end }}
183
+ }
184
+
185
+ object2 := {{ .ename }}Input{
186
+ {{- range $i, $field := .mapKeys }}
187
+ {{ $field }}: "2",
188
+ {{- end }}
189
+ }
190
+
191
+ t.Run("List", func(t *testing.T) {
192
+ require.Len(t, global.Items(), 0)
193
+ })
194
+
195
+ t.Run("Precheck", func(t *testing.T) {
196
+ require.EqualValues(t, 0, global.Get(object1))
197
+ require.EqualValues(t, 0, global.Get(object2))
198
+ })
199
+
200
+ t.Run("Add", func(t *testing.T) {
201
+ global.Add(object1, 10)
202
+
203
+ require.EqualValues(t, 10, global.Get(object1))
204
+ require.EqualValues(t, 0, global.Get(object2))
205
+ })
206
+
207
+ t.Run("List", func(t *testing.T) {
208
+ require.Len(t, global.Items(), 1)
209
+ })
210
+
211
+ t.Run("Set", func(t *testing.T) {
212
+ global.Set(object1, 3)
213
+ global.Set(object2, 1)
214
+
215
+ require.EqualValues(t, 3, global.Get(object1))
216
+ require.EqualValues(t, 1, global.Get(object2))
217
+ })
218
+
219
+ t.Run("List", func(t *testing.T) {
220
+ require.Len(t, global.Items(), 2)
221
+ })
222
+ }
223
+ {{- end }}
224
+
0 commit comments