コード例 #1
0
ファイル: folder_test.go プロジェクト: DanielKrawisz/bmagent
func testLastIDBySuffix(
	tc testContext, mbox store.Folder, suffix, expectedID uint64, note string) {

	_, lastIdBySfx := mbox.LastID()
	id := lastIdBySfx[suffix]
	if expectedID != id {
		tc.T().Errorf("%s, %s: For suffix %d, expected ID %d got %d",
			tc.Context(), note, suffix, expectedID, id)
	}
}
コード例 #2
0
ファイル: folder_test.go プロジェクト: DanielKrawisz/bmagent
func testDeleteMessage(tc testContext, mbox store.Folder, id uint64, note string) {
	err := mbox.DeleteMessage(id)
	if err != nil {
		tc.T().Errorf("%s, %s: For id %d got error %v", tc.Context(), note, id, err)
	}
	_, _, err = mbox.GetMessage(id)
	if err == nil {
		tc.T().Errorf("%s, %s: for id %d expected ErrNotFound got nil", tc.Context(), note, id)
	} else if err != store.ErrNotFound {
		tc.T().Errorf("%s, %s: For id %d got error %v", tc.Context(), note, id, err)
	}
}
コード例 #3
0
func testNextLast(tc testContext, folder store.Folder, exLast, exNext uint64, note string) {

	last, _ := folder.LastID()
	next := folder.NextID()

	if last != exLast {
		tc.T().Error(tc.Context(), ", ", note, ": new folder's last id should be ", exLast, " got ", last)
	}

	if next != exNext {
		tc.T().Error(tc.Context(), ", ", note, ": new folder's next id should be ", exNext, " got ", next)
	}

}
コード例 #4
0
ファイル: folder_test.go プロジェクト: DanielKrawisz/bmagent
func testForEachMessage(mbox store.Folder, lowID, highID, suffix,
	expectedCount uint64, t *testing.T) {

	counter := uint64(0)
	err := mbox.ForEachMessage(lowID, highID, suffix,
		func(index, suffix uint64, msg []byte) error {
			counter++
			return nil
		})
	if err != nil {
		t.Errorf("For lowID %d, highID %d, suffix %d, got error %v", lowID,
			highID, suffix, err)
	}
	if expectedCount != counter {
		t.Errorf("For lowID %d, highID %d, suffix %d, expected counter %d got %d",
			lowID, highID, suffix, expectedCount, counter)
	}
}
コード例 #5
0
ファイル: folder_test.go プロジェクト: DanielKrawisz/bmagent
func testInsertMessage(mbox store.Folder, msg []byte, suffix uint64,
	expectedID uint64, t *testing.T) {
	// Try inserting a new message.
	id, err := mbox.InsertNewMessage(msg, suffix)
	if err != nil {
		t.Errorf("For message #%d got error %v", expectedID, err)
	}
	if expectedID != id {
		t.Errorf("For message #%[1]d expected id %[1]d got %[2]d", expectedID,
			id)
	}

	last, _ := mbox.LastID()
	next := mbox.NextID()
	if last != id {
		t.Errorf("For message #%[1]d expected id %[1]d got %[2]d", id, last)
	}
	if next != id+1 {
		t.Errorf("For message #%[1]d expected id %[1]d got %[2]d", id+1, next)
	}

	// Try retrieving the same message.
	testSuffix, testMsg, err := mbox.GetMessage(id)
	if err != nil {
		t.Errorf("For message #%d got error %v", expectedID, err)
	}
	if suffix != testSuffix {
		t.Errorf("For message #%d expected suffix %d got %d", expectedID,
			suffix, testSuffix)
	}
	if !bytes.Equal(msg, testMsg) {
		t.Errorf(`For message #%d expected "%s" got "%s"`, expectedID,
			string(msg), string(testMsg))
	}

	// Try inserting message with the same ID but different suffix.
	err = mbox.InsertMessage(id, msg, suffix+1)
	if err != store.ErrDuplicateID {
		t.Errorf("For message #%d expected ErrDuplicateID got %v", expectedID, err)
	}
}
コード例 #6
0
// Test that err invalid index is returned
func testInvalidIndex(tc testContext, folder store.Folder, max uint64) {
	if err := folder.InsertMessage(0, nil, 0); err != store.ErrInvalidID {
		tc.T().Error("Expected ", store.ErrInvalidID, " got ", err)
	}

	if err := folder.InsertMessage(max, nil, 0); err != store.ErrInvalidID {
		tc.T().Error("Expected ", store.ErrInvalidID, " got ", err)
	}

	if _, _, err := folder.GetMessage(0); err != store.ErrNotFound {
		tc.T().Error("Expected ", store.ErrNotFound, " got ", err)
	}

	if _, _, err := folder.GetMessage(max); err != store.ErrNotFound {
		tc.T().Error("Expected ", store.ErrNotFound, " got ", err)
	}

	if err := folder.DeleteMessage(0); err != store.ErrInvalidID {
		tc.T().Error("Expected ", store.ErrInvalidID, " got ", err)
	}

	if err := folder.DeleteMessage(max); err != store.ErrInvalidID {
		tc.T().Error("Expected ", store.ErrInvalidID, " got ", err)
	}
}