MemoryBackend: handle config correctly, add tests for that

This commit is contained in:
Alexander Neumann 2015-11-22 16:38:58 +01:00
parent 538e5878a1
commit 480054bc3a
2 changed files with 43 additions and 1 deletions

View file

@ -103,11 +103,18 @@ func (e *tempMemEntry) Size() uint {
}
func (e *tempMemEntry) Finalize(t Type, name string) error {
if t == Config {
name = ""
}
debug.Log("MemoryBackend", "save blob %p as %v %v", e, t, name)
return e.be.insert(t, name, e.data.Bytes())
}
func memCreate(be *MemoryBackend) (Blob, error) {
return &tempMemEntry{be: be}, nil
blob := &tempMemEntry{be: be}
debug.Log("MemoryBackend.Create", "create new blob %p", blob)
return blob, nil
}
// readCloser wraps a reader and adds a noop Close method.
@ -123,6 +130,10 @@ func memGet(be *MemoryBackend, t Type, name string) (io.ReadCloser, error) {
be.m.Lock()
defer be.m.Unlock()
if t == Config {
name = ""
}
debug.Log("MemoryBackend.Get", "get %v %v", t, name)
if _, ok := be.data[entry{t, name}]; !ok {
@ -136,6 +147,10 @@ func memGetReader(be *MemoryBackend, t Type, name string, offset, length uint) (
be.m.Lock()
defer be.m.Unlock()
if t == Config {
name = ""
}
debug.Log("MemoryBackend.GetReader", "get %v %v", t, name)
if _, ok := be.data[entry{t, name}]; !ok {