From 75112d67e249b787c7cec8ccdba8cbe6d0fc1226 Mon Sep 17 00:00:00 2001 From: Alex Bramley Date: Thu, 27 Oct 2011 18:43:34 +0100 Subject: [PATCH] More nick tests. --- state/nick_test.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/state/nick_test.go b/state/nick_test.go index 1a20de7..5a2bae4 100644 --- a/state/nick_test.go +++ b/state/nick_test.go @@ -27,7 +27,7 @@ func TestAddChannel(t *testing.T) { m.CheckNothingWritten(t) if len(nk.chans) != 1 || len(nk.lookup) != 1 { - t.Errorf("Channel lists not updated correctly.") + t.Errorf("Channel lists not updated correctly for add.") } if c, ok := nk.chans[ch]; !ok || c != cp { t.Errorf("Channel #test1 not properly stored in chans map.") @@ -35,4 +35,32 @@ func TestAddChannel(t *testing.T) { if c, ok := nk.lookup["#test1"]; !ok || c != ch { t.Errorf("Channel #test1 not properly stored in lookup map.") } + + nk.addChannel(ch, cp) + m.CheckWrittenAtLevel(t, logging.Warn, + "Nick.addChannel(): test1 already on #test1.") +} + +func TestDelChannel(t *testing.T) { + l, m := logging.NewMock() + nk := NewNick("test1", l) + ch := NewChannel("#test1", l) + cp := new(ChanPrivs) + + // Testing the error state first is easier + nk.delChannel(ch) + m.CheckWrittenAtLevel(t, logging.Warn, + "Nick.delChannel(): test1 not on #test1.") + + nk.addChannel(ch, cp) + nk.delChannel(ch) + if len(nk.chans) != 0 || len(nk.lookup) != 0 { + t.Errorf("Channel lists not updated correctly for del.") + } + if c, ok := nk.chans[ch]; ok || c != nil { + t.Errorf("Channel #test1 not properly removed from chans map.") + } + if c, ok := nk.lookup["#test1"]; ok || c != nil { + t.Errorf("Channel #test1 not properly removed from lookup map.") + } }