MCPcopy Index your code
hub / github.com/tinylib/msgp / TestFieldLevelLimits

Function TestFieldLevelLimits

_generated/limits_test.go:399–518  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

397}
398
399func TestFieldLevelLimits(t *testing.T) {
400 // Test field-level limit enforcement with FieldLimitTestData
401
402 t.Run("SmallSlice_WithinLimit", func(t *testing.T) {
403 data := FieldLimitTestData{
404 SmallSlice: []int{1, 2, 3}, // Within limit of 5
405 }
406
407 // Marshal
408 marshaled, err := data.MarshalMsg(nil)
409 if err != nil {
410 t.Fatalf("Unexpected marshal error: %v", err)
411 }
412
413 // Unmarshal
414 var result FieldLimitTestData
415 _, err = result.UnmarshalMsg(marshaled)
416 if err != nil {
417 t.Fatalf("Unexpected unmarshal error: %v", err)
418 }
419
420 if len(result.SmallSlice) != len(data.SmallSlice) {
421 t.Errorf("SmallSlice length mismatch: got %d, want %d", len(result.SmallSlice), len(data.SmallSlice))
422 }
423 })
424
425 t.Run("SmallSlice_ExceedsLimit", func(t *testing.T) {
426 data := FieldLimitTestData{
427 SmallSlice: []int{1, 2, 3, 4, 5, 6, 7}, // Exceeds limit of 5
428 }
429
430 marshaled, err := data.MarshalMsg(nil)
431 if err != nil {
432 t.Fatalf("Unexpected marshal error: %v", err)
433 }
434
435 // Unmarshal should fail
436 var result FieldLimitTestData
437 _, err = result.UnmarshalMsg(marshaled)
438 if err == nil {
439 t.Error("Expected error for SmallSlice exceeding limit, got nil")
440 }
441 })
442
443 t.Run("SmallMap_WithinLimit", func(t *testing.T) {
444 data := FieldLimitTestData{
445 SmallMap: map[string]int{"a": 1, "b": 2}, // Within limit of 3
446 }
447
448 marshaled, err := data.MarshalMsg(nil)
449 if err != nil {
450 t.Fatalf("Unexpected marshal error: %v", err)
451 }
452
453 var result FieldLimitTestData
454 _, err = result.UnmarshalMsg(marshaled)
455 if err != nil {
456 t.Fatalf("Unexpected unmarshal error: %v", err)

Callers

nothing calls this directly

Calls 5

NewReaderFunction · 0.92
MarshalMsgMethod · 0.65
UnmarshalMsgMethod · 0.65
DecodeMsgMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…