MCPcopy Create free account
hub / github.com/buke/quickjs-go / TestHandleStore_EdgeCases

Function TestHandleStore_EdgeCases

handle_test.go:97–147  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

95}
96
97func TestHandleStore_EdgeCases(t *testing.T) {
98 t.Run("IDOverflow", func(t *testing.T) {
99 // Test ID overflow at MaxInt32
100 hs := newHandleStoreWithStartID(math.MaxInt32 - 2)
101
102 // First store should succeed
103 id1 := hs.Store("test1")
104 assert.Equal(t, int32(math.MaxInt32-1), id1)
105
106 // Second store should panic at MaxInt32
107 assert.Panics(t, func() {
108 hs.Store("test2")
109 })
110
111 assert.True(t, hs.Delete(id1))
112 })
113
114 t.Run("NegativeStartID", func(t *testing.T) {
115 // Test immediate panic with negative start ID
116 hs := newHandleStoreWithStartID(-1)
117 assert.Panics(t, func() {
118 hs.Store("test")
119 }, "Should panic when ID becomes 0")
120 })
121
122 t.Run("LoadNonExistent", func(t *testing.T) {
123 hs := newHandleStore()
124 value, ok := hs.Load(999)
125 assert.False(t, ok)
126 assert.Nil(t, value)
127 })
128
129 t.Run("DeleteNonExistent", func(t *testing.T) {
130 hs := newHandleStore()
131 success := hs.Delete(999)
132 assert.False(t, success)
133 })
134
135 t.Run("DoubleDelete", func(t *testing.T) {
136 hs := newHandleStore()
137 id := hs.Store("test")
138 assert.True(t, hs.Delete(id)) // First delete succeeds
139 assert.False(t, hs.Delete(id)) // Second delete fails
140 })
141
142 t.Run("ClearEmpty", func(t *testing.T) {
143 hs := newHandleStore()
144 hs.Clear() // Should not panic
145 assert.Equal(t, 0, hs.Count())
146 })
147}
148
149func TestHandleStore_FailClosedOnCorruptedEntries(t *testing.T) {
150 hs := newHandleStore()

Callers

nothing calls this directly

Calls 8

newHandleStoreFunction · 0.85
StoreMethod · 0.80
EqualMethod · 0.80
LoadMethod · 0.80
ClearMethod · 0.80
CountMethod · 0.80
DeleteMethod · 0.45

Tested by

no test coverage detected