NewInMemoryStorage uses the inmemory package to create a new in-memory storage that can be used for unit testing. The funcs varargs can be used to immediately execute storage operations on it.
(t *testing.T, funcs ...func(s persistence.Storage))
| 10 | // NewInMemoryStorage uses the inmemory package to create a new in-memory storage that can be used |
| 11 | // for unit testing. The funcs varargs can be used to immediately execute storage operations on it. |
| 12 | func NewInMemoryStorage(t *testing.T, funcs ...func(s persistence.Storage)) (s persistence.Storage) { |
| 13 | var err error |
| 14 | |
| 15 | s, err = inmemory.NewStorage() |
| 16 | if err != nil { |
| 17 | t.Fatalf("Could not initialize in-memory db: %v", err) |
| 18 | } |
| 19 | |
| 20 | for _, f := range funcs { |
| 21 | f(s) |
| 22 | } |
| 23 | |
| 24 | return |
| 25 | } |
| 26 | |
| 27 | // StorageWithError can be used to introduce various errors in a storage operation during unit testing. |
| 28 | type StorageWithError struct { |