예제 #1
0
func TestBulk(t *testing.T) {
	t.Parallel()

	bulk := new(couch.Bulk)
	bulk.Add(&Person{Name: "Peter", Height: 160})
	bulk.Add(&Person{Name: "Anna", Height: 170})

	bulk.Docs[0].SetIDRev("1", "A")
	bulk.Docs[1].SetIDRev("2", "B")

	doc := bulk.Find("2", "C")
	if doc != nil {
		t.Error("Looking for non-existing doc in bulk, found something", doc)
	}
	doc = bulk.Find("2", "B")
	if doc == nil {
		t.Error("Looking for existing doc in bulk, not found")
	}
}
예제 #2
0
func TestIntegrationBulkInsert(t *testing.T) {
	db := setUpDatabase(t)
	defer tearDownDatabase(db, t)

	bulk := new(couch.Bulk)
	bulk.Add(&Person{Name: "Peter", Height: 160})
	bulk.Add(&Person{Name: "Anna", Height: 170})
	bulk.Add(&Person{Name: "Stefan", Height: 180})

	failedBulk, err := db.InsertBulk(bulk, true)
	if err != nil {
		t.Fatal("Inserting bulk of documents returns error:", err, "failed docs:", failedBulk.Docs)
	}

	for _, doc := range bulk.Docs {
		id, rev := doc.IDRev()
		if id == "" || rev == "" {
			t.Error("Newly added document in bulk should have id and rev set after opereration but doesn't:", doc)
		}
	}
}