namespace: finish tests

Change-Id: Ib34364473e407e78fd691256ad1afe8c810911a9
This commit is contained in:
Brad Fitzpatrick 2014-01-20 13:08:37 -08:00
parent 31125295a4
commit d5ec2925dd
1 changed files with 72 additions and 5 deletions

View File

@ -17,15 +17,18 @@ limitations under the License.
package namespace
import (
"reflect"
"sort"
"testing"
"camlistore.org/pkg/blob"
"camlistore.org/pkg/blobserver"
"camlistore.org/pkg/blobserver/storagetest"
"camlistore.org/pkg/context"
"camlistore.org/pkg/test"
)
func newTestNamespace(t *testing.T) (sto blobserver.Storage, cleanup func()) {
ld := test.NewLoader()
func newNamespace(t *testing.T, ld *test.Loader) *nsto {
sto, err := newFromConfig(ld, map[string]interface{}{
"storage": "/good-storage/",
"inventory": map[string]interface{}{
@ -35,9 +38,73 @@ func newTestNamespace(t *testing.T) (sto blobserver.Storage, cleanup func()) {
if err != nil {
t.Fatal(err)
}
return sto, func() {}
return sto.(*nsto)
}
func TestNamespace(t *testing.T) {
storagetest.Test(t, newTestNamespace)
func TestStorageTest(t *testing.T) {
storagetest.Test(t, func(t *testing.T) (sto blobserver.Storage, cleanup func()) {
ld := test.NewLoader()
return newNamespace(t, ld), func() {}
})
}
func TestIsolation(t *testing.T) {
ld := test.NewLoader()
master, _ := ld.GetStorage("/good-storage/")
ns1 := newNamespace(t, ld)
ns2 := newNamespace(t, ld)
stoMap := map[string]blobserver.Storage{
"ns1": ns1,
"ns2": ns2,
"master": master,
}
want := func(src string, want ...blob.Ref) {
if _, ok := stoMap[src]; !ok {
t.Fatalf("undefined storage %q", src)
}
sort.Sort(blob.ByRef(want))
var got []blob.Ref
if err := blobserver.EnumerateAll(context.TODO(), stoMap[src], func(sb blob.SizedRef) error {
got = append(got, sb.Ref)
return nil
}); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(got, want) {
t.Errorf("server %q = %q; want %q", src, got, want)
}
}
b1 := &test.Blob{Contents: "Blob 1"}
b1r := b1.BlobRef()
b2 := &test.Blob{Contents: "Blob 2"}
b2r := b2.BlobRef()
b3 := &test.Blob{Contents: "Shared Blob"}
b3r := b3.BlobRef()
b1.MustUpload(t, ns1)
want("ns1", b1r)
want("ns2")
want("master", b1r)
b2.MustUpload(t, ns2)
want("ns1", b1r)
want("ns2", b2r)
want("master", b1r, b2r)
b3.MustUpload(t, ns2)
want("ns1", b1r)
want("ns2", b2r, b3r)
want("master", b1r, b2r, b3r)
b3.MustUpload(t, ns1)
want("ns1", b1r, b3r)
want("ns2", b2r, b3r)
want("master", b1r, b2r, b3r)
if _, _, err := ns2.FetchStreaming(b1r); err == nil {
t.Errorf("b1 shouldn't be accessible via ns2")
}
}