MCPcopy
hub / github.com/kopia/kopia / TestInt32

Function TestInt32

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

Source from the content-addressed store, hash-verified

222}
223
224func TestInt32(t *testing.T) {
225 tests := []struct {
226 name string
227 key string
228 value int32
229 expected map[string]any
230 }{
231 {
232 name: "positive int32",
233 key: "count",
234 value: 2147483647,
235 expected: map[string]any{
236 "count": 2147483647.0,
237 },
238 },
239 {
240 name: "negative int32",
241 key: "negative",
242 value: -2147483648,
243 expected: map[string]any{
244 "negative": -2147483648.0,
245 },
246 },
247 {
248 name: "zero int32",
249 key: "zero",
250 value: 0,
251 expected: map[string]any{
252 "zero": 0.0,
253 },
254 },
255 }
256
257 for _, tt := range tests {
258 t.Run(tt.name, func(t *testing.T) {
259 // Test memory allocations
260 allocs := testing.AllocsPerRun(100, func() {
261 _ = Int32(tt.key, tt.value)
262 })
263 require.Equal(t, float64(0), allocs, "Int32() should not allocate memory")
264
265 // Test output format
266 param := Int32(tt.key, tt.value)
267
268 jw := contentlog.NewJSONWriter()
269 defer jw.Release()
270
271 jw.BeginObject()
272 param.WriteValueTo(jw)
273 jw.EndObject()
274
275 var result map[string]any
276
277 require.NoError(t, json.Unmarshal(jw.GetBufferForTesting(), &result))
278 require.Equal(t, tt.expected, result)
279 })
280 }
281}

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected