X-Git-Url: http://git.scottworley.com/reliable-chat/blobdiff_plain/b199796a3d2c82a84243e3a5ad3099315d8f1b55..591b51678a352ec65de07c3f4dc79f63156ca605:/server/server_test.go?ds=sidebyside diff --git a/server/server_test.go b/server/server_test.go index 0634b8f..208256d 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -1,3 +1,20 @@ +/* reliable-chat - multipath chat + * Copyright (C) 2012 Scott Worley + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package main import "testing" @@ -5,6 +22,18 @@ import "runtime" import "strconv" import "time" +func expectMessage(t *testing.T, m *Message, at time.Time, id, say string) { + if m.Time != at { + t.Fail() + } + if m.ID != id { + t.Fail() + } + if m.Text != say { + t.Fail() + } +} + func TestMessageInsertAndRetreive(t *testing.T) { id := "1" say := "'Ello, Mister Polly Parrot!" @@ -18,15 +47,7 @@ func TestMessageInsertAndRetreive(t *testing.T) { if len(messages) != 1 { t.FailNow() } - if messages[0].Time != at { - t.Fail() - } - if messages[0].ID != id { - t.Fail() - } - if messages[0].Text != say { - t.Fail() - } + expectMessage(t, &messages[0], at, id, say) close(store.Get) close(store.Add) } @@ -48,15 +69,7 @@ func TestFetchBlocksUntilSpeak(t *testing.T) { if len(messages) != 1 { t.FailNow() } - if messages[0].Time != at { - t.Fail() - } - if messages[0].ID != id { - t.Fail() - } - if messages[0].Text != say { - t.Fail() - } + expectMessage(t, &messages[0], at, id, say) close(store.Get) close(store.Add) } @@ -79,15 +92,7 @@ func TestMultipleListeners(t *testing.T) { if len(messages) != 1 { t.FailNow() } - if messages[0].Time != at { - t.Fail() - } - if messages[0].ID != id { - t.Fail() - } - if messages[0].Text != say { - t.Fail() - } + expectMessage(t,& messages[0], at, id, say) } close(store.Get) close(store.Add) @@ -135,24 +140,8 @@ func TestPartialRetreive(t *testing.T) { if len(messages) != 2 { t.FailNow() } - if messages[0].Time != at2 { - t.Fail() - } - if messages[0].ID != id2 { - t.Fail() - } - if messages[0].Text != say2 { - t.Fail() - } - if messages[1].Time != at3 { - t.Fail() - } - if messages[1].ID != id3 { - t.Fail() - } - if messages[1].Text != say3 { - t.Fail() - } + expectMessage(t, &messages[0], at2, id2, say2) + expectMessage(t, &messages[1], at3, id3, say3) close(store.Get) close(store.Add) } @@ -183,15 +172,7 @@ func TestPrecisePartialRetreive(t *testing.T) { if len(messages) != 1 { t.FailNow() } - if messages[0].Time != at3 { - t.Fail() - } - if messages[0].ID != id3 { - t.Fail() - } - if messages[0].Text != say3 { - t.Fail() - } + expectMessage(t, &messages[0], at3, id3, say3) close(store.Get) close(store.Add) } @@ -219,15 +200,7 @@ func TestTypicalFlow(t *testing.T) { if len(messages1) != 1 { t.FailNow() } - if messages1[0].Time != at1 { - t.Fail() - } - if messages1[0].ID != id1 { - t.Fail() - } - if messages1[0].Text != say1 { - t.Fail() - } + expectMessage(t, &messages1[0], at1, id1, say1) // Upon recipt, client blocks on fetch with since=at1 prev_fetch_wait_count = fetch_wait_count.String() @@ -247,15 +220,7 @@ func TestTypicalFlow(t *testing.T) { if len(messages2) != 1 { t.FailNow() } - if messages2[0].Time != at2 { - t.Fail() - } - if messages2[0].ID != id2 { - t.Fail() - } - if messages2[0].Text != say2 { - t.Fail() - } + expectMessage(t, &messages2[0], at2, id2, say2) close(store.Get) close(store.Add)