MCPcopy
hub / github.com/tinylib/msgp / TestSliceLimitsApplied

Function TestSliceLimitsApplied

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

Source from the content-addressed store, hash-verified

136}
137
138func TestSliceLimitsApplied(t *testing.T) {
139 // Test that dynamic slices are subject to limits
140 data := UnlimitedData{}
141
142 t.Run("Slice_ExceedsLimit", func(t *testing.T) {
143 buf := msgp.AppendMapHeader(nil, 1)
144 buf = msgp.AppendString(buf, "big_slice")
145 buf = msgp.AppendArrayHeader(buf, 150) // Exceeds array limit of 100
146
147 _, err := data.UnmarshalMsg(buf)
148 if err != msgp.ErrLimitExceeded {
149 t.Errorf("Expected ErrLimitExceeded for slice, got %v", err)
150 }
151 })
152
153 t.Run("Slice_WithinLimit", func(t *testing.T) {
154 buf := msgp.AppendMapHeader(nil, 1)
155 buf = msgp.AppendString(buf, "big_slice")
156 buf = msgp.AppendArrayHeader(buf, 50) // Within array limit of 100
157 for i := 0; i < 50; i++ {
158 buf = msgp.AppendString(buf, "test")
159 }
160
161 _, err := data.UnmarshalMsg(buf)
162 if err != nil {
163 t.Errorf("Unexpected error for slice within limit: %v", err)
164 }
165 })
166}
167
168func TestNestedArrayLimits(t *testing.T) {
169 // Test limits on nested arrays within maps

Callers

nothing calls this directly

Calls 4

AppendMapHeaderFunction · 0.92
AppendStringFunction · 0.92
AppendArrayHeaderFunction · 0.92
UnmarshalMsgMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…