Beispiel #1
0
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)
	}
}