1
0
Fork 0
forked from mirrors/tar-split

tar/storage: do not accept duplicate paths

This commit is contained in:
Vincent Batts 2015-02-27 16:53:31 -05:00
parent 891685f740
commit cfd32ecbc4
2 changed files with 82 additions and 10 deletions

View file

@ -7,6 +7,39 @@ import (
"testing"
)
func TestDuplicateFail(t *testing.T) {
e := []Entry{
Entry{
Type: FileType,
Name: "./hurr.txt",
Payload: []byte("abcde"),
},
Entry{
Type: FileType,
Name: "./hurr.txt",
Payload: []byte("deadbeef"),
},
Entry{
Type: FileType,
Name: "hurr.txt", // slightly different path, same file though
Payload: []byte("deadbeef"),
},
}
buf := []byte{}
b := bytes.NewBuffer(buf)
jp := NewJsonPacker(b)
if _, err := jp.AddEntry(e[0]); err != nil {
t.Error(err)
}
if _, err := jp.AddEntry(e[1]); err != ErrDuplicatePath {
t.Errorf("expected failure on duplicate path")
}
if _, err := jp.AddEntry(e[2]); err != ErrDuplicatePath {
t.Errorf("expected failure on duplicate path")
}
}
func TestJsonPackerUnpacker(t *testing.T) {
e := []Entry{
Entry{