Move underscore tests to file from physical testing

This commit is contained in:
Jeff Mitchell 2017-10-26 15:29:10 -04:00
parent 28b0db38cc
commit 8a610e1e78
2 changed files with 61 additions and 60 deletions

View file

@ -173,5 +173,66 @@ func TestFileBackend(t *testing.T) {
} }
physical.ExerciseBackend(t, b) physical.ExerciseBackend(t, b)
// Underscores should not trip things up; ref GH-3476
e := &physical.Entry{Key: "_zip", Value: []byte("foobar")}
err = b.Put(e)
if err != nil {
t.Fatalf("err: %v", err)
}
e = &physical.Entry{Key: "_zip/_zap", Value: []byte("boofar")}
err = b.Put(e)
if err != nil {
t.Fatalf("err: %v", err)
}
e, err = b.Get("_zip/_zap")
if err != nil {
t.Fatalf("err: %v", err)
}
if e == nil {
t.Fatal("got nil entry")
}
vals, err := b.List("")
if err != nil {
t.Fatal(err)
}
if len(vals) != 2 || vals[0] == vals[1] {
t.Fatalf("bad: %v", vals)
}
for _, val := range vals {
if val != "_zip/" && val != "_zip" {
t.Fatalf("bad val: %v", val)
}
}
vals, err = b.List("_zip/")
if err != nil {
t.Fatal(err)
}
if len(vals) != 1 || vals[0] != "_zap" {
t.Fatalf("bad: %v", vals)
}
err = b.Delete("_zip/_zap")
if err != nil {
t.Fatal(err)
}
vals, err = b.List("")
if err != nil {
t.Fatal(err)
}
if len(vals) != 1 || vals[0] != "_zip" {
t.Fatalf("bad: %v", vals)
}
err = b.Delete("_zip")
if err != nil {
t.Fatal(err)
}
vals, err = b.List("")
if err != nil {
t.Fatal(err)
}
if len(vals) != 0 {
t.Fatalf("bad: %v", vals)
}
physical.ExerciseBackend_ListPrefix(t, b) physical.ExerciseBackend_ListPrefix(t, b)
} }

View file

@ -194,66 +194,6 @@ func ExerciseBackend(t *testing.T, b Backend) {
if len(keys) != 0 { if len(keys) != 0 {
t.Fatalf("bad: %v", keys) t.Fatalf("bad: %v", keys)
} }
// Underscores should not trip things up; ref GH-3476
e = &Entry{Key: "_zip", Value: []byte("foobar")}
err = b.Put(e)
if err != nil {
t.Fatalf("err: %v", err)
}
e = &Entry{Key: "_zip/_zap", Value: []byte("boofar")}
err = b.Put(e)
if err != nil {
t.Fatalf("err: %v", err)
}
e, err = b.Get("_zip/_zap")
if err != nil {
t.Fatalf("err: %v", err)
}
if e == nil {
t.Fatal("got nil entry")
}
vals, err := b.List("")
if err != nil {
t.Fatal(err)
}
if len(vals) != 2 || vals[0] == vals[1] {
t.Fatalf("bad: %v", vals)
}
for _, val := range vals {
if val != "_zip/" && val != "_zip" {
t.Fatalf("bad val: %v", val)
}
}
vals, err = b.List("_zip/")
if err != nil {
t.Fatal(err)
}
if len(vals) != 1 || vals[0] != "_zap" {
t.Fatalf("bad: %v", vals)
}
err = b.Delete("_zip/_zap")
if err != nil {
t.Fatal(err)
}
vals, err = b.List("")
if err != nil {
t.Fatal(err)
}
if len(vals) != 1 || vals[0] != "_zip" {
t.Fatalf("bad: %v", vals)
}
err = b.Delete("_zip")
if err != nil {
t.Fatal(err)
}
vals, err = b.List("")
if err != nil {
t.Fatal(err)
}
if len(vals) != 0 {
t.Fatalf("bad: %v", vals)
}
} }
func ExerciseBackend_ListPrefix(t *testing.T, b Backend) { func ExerciseBackend_ListPrefix(t *testing.T, b Backend) {