Write layout: 0 1 2 3 4 5 6 7 8 9 10 11 ┌────╔════╤════╤════╗────┬────┬────┬────┬────┬────┬────┬────┐ 0 │ ║A 10│ 11 │ 12 ║ │ │ │ │ │ │ │ │ └────╚════╧════╧════╝────┴────┴────┴────┴────┴────┴────┴────┘ ┌────┬────┬────┬────┬────┬────┬────╔════╤
(t *testing.T)
| 172 | // └────┴────┴────┴────┴────┴────┴────┴────╚════╝────┴────┴────┘ |
| 173 | // |
| 174 | func TestMemoryResourceWriteReadScattered(t *testing.T) { |
| 175 | ctx := log.Testing(t) |
| 176 | ctx = database.Put(ctx, database.NewInMemory(ctx)) |
| 177 | resA, _ := database.Store(ctx, []byte{10, 11, 12}) |
| 178 | resB, _ := database.Store(ctx, []byte{20, 21, 22, 23}) |
| 179 | resC, _ := database.Store(ctx, []byte{30, 31}) |
| 180 | resD, _ := database.Store(ctx, []byte{40, 41, 42}) |
| 181 | resE, _ := database.Store(ctx, []byte{50}) |
| 182 | |
| 183 | p := Pool{} |
| 184 | p.Write(1, Resource(resA, 3)) |
| 185 | p.Write(7, Resource(resB, 4)) |
| 186 | p.Write(2, Resource(resC, 2)) |
| 187 | p.Write(2, Resource(resD, 3)) |
| 188 | p.Write(8, Resource(resE, 1)) |
| 189 | |
| 190 | for _, test := range []struct { |
| 191 | rng Range |
| 192 | expected []byte |
| 193 | }{ |
| 194 | {Range{Base: 0, Size: 12}, []byte{0, 10, 40, 41, 42, 00, 00, 20, 50, 22, 23, 00}}, |
| 195 | {Range{Base: 1, Size: 10}, []byte{10, 40, 41, 42, 00, 00, 20, 50, 22, 23}}, |
| 196 | {Range{Base: 2, Size: 3}, []byte{40, 41, 42}}, |
| 197 | {Range{Base: 5, Size: 2}, []byte{0, 0}}, |
| 198 | {Range{Base: 8, Size: 1}, []byte{50}}, |
| 199 | } { |
| 200 | slice := p.Slice(test.rng) |
| 201 | checkData(ctx, slice, test.expected) |
| 202 | |
| 203 | gotID, err := slice.ResourceID(ctx) |
| 204 | assert.For(ctx, "err").ThatError(err).Succeeded() |
| 205 | |
| 206 | expectedID, _ := database.Store(ctx, test.expected) |
| 207 | assert.For(ctx, "id").That(gotID).Equals(expectedID) |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | func TestPoolSliceReaderErrorPropagation(t *testing.T) { |
| 212 | ctx := log.Testing(t) |
nothing calls this directly
no test coverage detected