Example #1
0
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")
	}
}
Example #2
0
func TestReceiveIsSchema(t *testing.T) {
	ld := test.NewLoader()
	sto := newCond(t, ld, map[string]interface{}{
		"write": map[string]interface{}{
			"if":   "isSchema",
			"then": "/good-schema/",
			"else": "/good-other/",
		},
		"read": "/good-other/",
	})
	otherBlob := &test.Blob{Contents: "stuff"}
	schemaBlob := &test.Blob{Contents: `{"camliVersion": 1, "camliType": "foo"}`}

	ssb := mustReceive(t, sto, schemaBlob)
	osb := mustReceive(t, sto, otherBlob)

	ssto, _ := ld.GetStorage("/good-schema/")
	osto, _ := ld.GetStorage("/good-other/")

	if _, err := blobserver.StatBlob(ssto, ssb.Ref); err != nil {
		t.Errorf("schema blob didn't end up on schema storage")
	}
	if _, err := blobserver.StatBlob(osto, osb.Ref); err != nil {
		t.Errorf("other blob didn't end up on other storage")
	}
}
func newReplica(t *testing.T, config jsonconfig.Obj) *replicaStorage {
	ld := test.NewLoader()
	sto, err := newFromConfig(ld, config)
	if err != nil {
		t.Fatalf("Invalid config: %v", err)
	}
	return sto.(*replicaStorage)
}
Example #4
0
func TestStorageTest(t *testing.T) {
	storagetest.Test(t, func(t *testing.T) (_ blobserver.Storage, cleanup func()) {
		ld := test.NewLoader()
		s1, _ := ld.GetStorage("/good-schema/")
		s2, _ := ld.GetStorage("/good-other/")
		ld.SetStorage("/replica-all/", replica.NewForTest([]blobserver.Storage{s1, s2}))
		sto := newCond(t, ld, map[string]interface{}{
			"write": map[string]interface{}{
				"if":   "isSchema",
				"then": "/good-schema/",
				"else": "/good-other/",
			},
			"read":   "/replica-all/",
			"remove": "/replica-all/",
		})
		return sto, func() {}
	})
}
Example #5
0
func TestStaticConfig(t *testing.T) {
	ld := test.NewLoader()
	h, err := newFromConfig(ld, jsonconfig.Obj{
		"dummy1": map[string]interface{}{
			"clientID":     "id1",
			"clientSecret": "secret1",
		},
		"dummy2": map[string]interface{}{
			"clientSecret": "id2:secret2",
		},
	})
	if err != nil {
		t.Fatal(err)
	}
	host := h.(*Host)
	if g, w := host.imp["dummy1"].clientID, "id1"; g != w {
		t.Errorf("dummy1 id = %q; want %q", g, w)
	}
	if g, w := host.imp["dummy1"].clientSecret, "secret1"; g != w {
		t.Errorf("dummy1 secret = %q; want %q", g, w)
	}
	if g, w := host.imp["dummy2"].clientID, "id2"; g != w {
		t.Errorf("dummy2 id = %q; want %q", g, w)
	}
	if g, w := host.imp["dummy2"].clientSecret, "secret2"; g != w {
		t.Errorf("dummy2 secret = %q; want %q", g, w)
	}

	if _, err := newFromConfig(ld, jsonconfig.Obj{"dummy1": map[string]interface{}{"bogus": ""}}); err == nil {
		t.Errorf("expected error from unknown key")
	}

	if _, err := newFromConfig(ld, jsonconfig.Obj{"dummy1": map[string]interface{}{"clientSecret": "x"}}); err == nil {
		t.Errorf("expected error from secret without id")
	}
}
Example #6
0
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() {}
	})
}