1
0
Fork 1
mirror of https://github.com/vbatts/tar-split.git synced 2024-12-19 11:56:30 +00:00

tar/asm: tests and fix

This commit is contained in:
Vincent Batts 2015-02-28 12:47:55 -05:00
parent 0c9efa4324
commit ccf6fa61a6
2 changed files with 39 additions and 1 deletions

View file

@ -65,6 +65,11 @@ type readCloserWrapper struct {
func (w *readCloserWrapper) Close() error { return nil }
// NewBufferFileGetPutter is simple in memory FileGetPutter
//
// Implication is this is memory intensive...
// Probably best for testing or light weight cases.
func NewBufferFileGetPutter() FileGetPutter {
return &bufferFileGetPutter{}
return &bufferFileGetPutter{
files: map[string][]byte{},
}
}

33
tar/asm/getter_test.go Normal file
View file

@ -0,0 +1,33 @@
package asm
import (
"bytes"
"io/ioutil"
"testing"
)
func TestGetter(t *testing.T) {
fgp := NewBufferFileGetPutter()
files := map[string][]byte{
"file1.txt": []byte("foo"),
"file2.txt": []byte("bar"),
}
for n, b := range files {
if err := fgp.Put(n, bytes.NewBuffer(b)); err != nil {
t.Error(err)
}
}
for n, b := range files {
r, err := fgp.Get(n)
if err != nil {
t.Error(err)
}
buf, err := ioutil.ReadAll(r)
if err != nil {
t.Error(err)
}
if string(b) != string(buf) {
t.Errorf("expected %q, got %q", string(b), string(buf))
}
}
}