Example #1
0
func Clearstore(t *testing.T, store cloudstorage.Store) {
	t.Logf("----------------Clearstore-----------------\n")
	q := cloudstorage.Query{"", nil}
	q.Sorted()
	objs, err := store.List(q)
	AssertEq(t, nil, err, "error.")
	for _, o := range objs {
		t.Logf("clearstore(): deleting %v", o.Name())
		store.Delete(o.Name())
	}

	if os.Getenv("TESTINT") != "" {
		//GCS is lazy about deletes...
		time.Sleep(15 * time.Second)
	}
}
Example #2
0
func TestListObjs(t *testing.T) {
	store := testutils.CreateStore(t)
	testutils.Clearstore(t, store)
	//
	//Create 20 objects
	//
	names := []string{}
	for i := 0; i < 20; i++ {
		n := fmt.Sprintf("list-test/test%d.csv", i)
		names = append(names, n)
	}

	sort.Strings(names)

	for _, n := range names {
		obj, err := store.NewObject(n)
		testutils.AssertEq(t, nil, err, "error. %v", obj)

		f1, err := obj.Open(cloudstorage.ReadWrite)
		testutils.AssertEq(t, nil, err, "error.")
		testutils.AssertT(t, f1 != nil, "the file was nil")

		testcsv := "12345\n"

		w1 := bufio.NewWriter(f1)
		n1, err := w1.WriteString(testcsv)
		testutils.AssertEq(t, nil, err, "error. %d", n1)
		w1.Flush()

		err = obj.Close()
		testutils.AssertEq(t, nil, err, "error.")
	}

	q := cloudstorage.Query{"list-test/", nil}
	q.Sorted()
	objs, err := store.List(q)
	testutils.AssertEq(t, nil, err, "error.")

	testutils.AssertEq(t, 20, len(objs), "incorrect list len.")

	for i, o := range objs {
		//t.Logf("%i found %v", i, o.Name())
		testutils.AssertEq(t, names[i], o.Name(), "unexpected name.")
	}

}