mirror of
https://github.com/vbatts/tar-split.git
synced 2024-12-19 20:06:30 +00:00
tar/asm: tests and fix
This commit is contained in:
parent
0c9efa4324
commit
ccf6fa61a6
2 changed files with 39 additions and 1 deletions
|
@ -65,6 +65,11 @@ type readCloserWrapper struct {
|
||||||
func (w *readCloserWrapper) Close() error { return nil }
|
func (w *readCloserWrapper) Close() error { return nil }
|
||||||
|
|
||||||
// NewBufferFileGetPutter is simple in memory FileGetPutter
|
// NewBufferFileGetPutter is simple in memory FileGetPutter
|
||||||
|
//
|
||||||
|
// Implication is this is memory intensive...
|
||||||
|
// Probably best for testing or light weight cases.
|
||||||
func NewBufferFileGetPutter() FileGetPutter {
|
func NewBufferFileGetPutter() FileGetPutter {
|
||||||
return &bufferFileGetPutter{}
|
return &bufferFileGetPutter{
|
||||||
|
files: map[string][]byte{},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
33
tar/asm/getter_test.go
Normal file
33
tar/asm/getter_test.go
Normal 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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue