MCPcopy Create free account
hub / github.com/ByteStorage/FlyDB / TestInMemStore_Set

Function TestInMemStore_Set

lib/datastore/inmem_test.go:157–206  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

155}
156
157func TestInMemStore_Set(t *testing.T) {
158 ds := testMemoryDatastore()
159 type kv struct {
160 key string
161 val string
162 }
163 type test struct {
164 input []kv
165 expectError bool
166 }
167 tests := []test{
168 {
169 input: []kv{
170 {key: "1", val: "2"},
171 {key: "foo", val: "bar"},
172 {key: "hello", val: "world"},
173 },
174 expectError: false,
175 },
176 {
177 input: []kv{
178 {key: "", val: "bar"},
179 },
180 expectError: true,
181 },
182 }
183 for _, tc := range tests {
184 // set all inputs
185 for _, v := range tc.input {
186 err := ds.Set(stringToBytes(v.key), stringToBytes(v.val))
187 if tc.expectError {
188 assert.NotNil(t, err)
189 } else {
190 assert.NoError(t, err)
191 }
192 }
193 // recall all inputs
194 for _, v := range tc.input {
195 val, err := ds.Get(stringToBytes(v.key))
196 if tc.expectError {
197 assert.NotNil(t, err)
198 } else {
199 assert.NoError(t, err)
200 assert.Equal(t, v.val, string(val))
201 }
202 }
203
204 }
205
206}
207func TestInMemStore_Get(t *testing.T) {
208 type kv struct {
209 key string

Callers

nothing calls this directly

Calls 4

testMemoryDatastoreFunction · 0.85
stringToBytesFunction · 0.85
SetMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected