MCPcopy
hub / github.com/kopia/kopia / TestInt

Function TestInt

internal/contentlog/logparam/logparam_test.go:165–222  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

163}
164
165func TestInt(t *testing.T) {
166 tests := []struct {
167 name string
168 key string
169 value int
170 expected map[string]any
171 }{
172 {
173 name: "positive int",
174 key: "count",
175 value: 42,
176 expected: map[string]any{
177 "count": 42.0,
178 },
179 },
180 {
181 name: "negative int",
182 key: "negative",
183 value: -100,
184 expected: map[string]any{
185 "negative": -100.0,
186 },
187 },
188 {
189 name: "zero int",
190 key: "zero",
191 value: 0,
192 expected: map[string]any{
193 "zero": 0.0,
194 },
195 },
196 }
197
198 for _, tt := range tests {
199 t.Run(tt.name, func(t *testing.T) {
200 // Test memory allocations
201 allocs := testing.AllocsPerRun(100, func() {
202 _ = Int(tt.key, tt.value)
203 })
204 require.Equal(t, float64(0), allocs, "Int() should not allocate memory")
205
206 // Test output format
207 param := Int(tt.key, tt.value)
208
209 jw := contentlog.NewJSONWriter()
210 defer jw.Release()
211
212 jw.BeginObject()
213 param.WriteValueTo(jw)
214 jw.EndObject()
215
216 var result map[string]any
217
218 require.NoError(t, json.Unmarshal(jw.GetBufferForTesting(), &result))
219 require.Equal(t, tt.expected, result)
220 })
221 }
222}

Callers

nothing calls this directly

Calls 9

ReleaseMethod · 0.95
BeginObjectMethod · 0.95
EndObjectMethod · 0.95
GetBufferForTestingMethod · 0.95
NewJSONWriterFunction · 0.92
IntFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
WriteValueToMethod · 0.65

Tested by

no test coverage detected