+/* reliable-chat - multipath chat
+ * Copyright (C) 2012 Scott Worley <sworley@chkno.net>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
package main
import "testing"
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!"
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)
}
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)
}
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)
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)
}
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)
}
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()
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)