Shave the yaks in state's tests.

This commit is contained in:
Alex Bramley 2011-11-05 06:06:40 +00:00
parent 588a3168ac
commit fdba74e8c0
3 changed files with 78 additions and 101 deletions

View File

@ -6,7 +6,7 @@ import (
) )
func TestNewChannel(t *testing.T) { func TestNewChannel(t *testing.T) {
l, _ := logging.NewMock() l, _ := logging.NewMock(t)
ch := NewChannel("#test1", l) ch := NewChannel("#test1", l)
if ch.Name != "#test1" || ch.l != l { if ch.Name != "#test1" || ch.l != l {
@ -18,13 +18,13 @@ func TestNewChannel(t *testing.T) {
} }
func TestAddNick(t *testing.T) { func TestAddNick(t *testing.T) {
l, m := logging.NewMock() l, m := logging.NewMock(t)
ch := NewChannel("#test1", l) ch := NewChannel("#test1", l)
nk := NewNick("test1", l) nk := NewNick("test1", l)
cp := new(ChanPrivs) cp := new(ChanPrivs)
ch.addNick(nk, cp) ch.addNick(nk, cp)
m.CheckNothingWritten(t) m.ExpectNothing()
if len(ch.nicks) != 1 || len(ch.lookup) != 1 { if len(ch.nicks) != 1 || len(ch.lookup) != 1 {
t.Errorf("Nick lists not updated correctly for add.") t.Errorf("Nick lists not updated correctly for add.")
@ -37,20 +37,18 @@ func TestAddNick(t *testing.T) {
} }
ch.addNick(nk, cp) ch.addNick(nk, cp)
m.CheckWrittenAtLevel(t, logging.Warn, m.ExpectAt(logging.Warn, "Channel.addNick(): test1 already on #test1.")
"Channel.addNick(): test1 already on #test1.")
} }
func TestDelNick(t *testing.T) { func TestDelNick(t *testing.T) {
l, m := logging.NewMock() l, m := logging.NewMock(t)
ch := NewChannel("#test1", l) ch := NewChannel("#test1", l)
nk := NewNick("test1", l) nk := NewNick("test1", l)
cp := new(ChanPrivs) cp := new(ChanPrivs)
// Testing the error state first is easier // Testing the error state first is easier
ch.delNick(nk) ch.delNick(nk)
m.CheckWrittenAtLevel(t, logging.Warn, m.ExpectAt(logging.Warn, "Channel.delNick(): test1 not on #test1.")
"Channel.delNick(): test1 not on #test1.")
ch.addNick(nk, cp) ch.addNick(nk, cp)
ch.delNick(nk) ch.delNick(nk)
@ -66,7 +64,7 @@ func TestDelNick(t *testing.T) {
} }
func TestChannelParseModes(t *testing.T) { func TestChannelParseModes(t *testing.T) {
l, m := logging.NewMock() l, m := logging.NewMock(t)
ch := NewChannel("#test1", l) ch := NewChannel("#test1", l)
md := ch.Modes md := ch.Modes
@ -88,7 +86,7 @@ func TestChannelParseModes(t *testing.T) {
// Flip some MOAR bits. // Flip some MOAR bits.
ch.ParseModes("+s-p+tm-i") ch.ParseModes("+s-p+tm-i")
m.CheckNothingWritten(t) m.ExpectNothing()
if md.Private || !md.Secret || !md.ProtectedTopic || !md.NoExternalMsg || if md.Private || !md.Secret || !md.ProtectedTopic || !md.NoExternalMsg ||
!md.Moderated || md.InviteOnly || md.OperOnly || md.SSLOnly { !md.Moderated || md.InviteOnly || md.OperOnly || md.SSLOnly {
@ -102,14 +100,14 @@ func TestChannelParseModes(t *testing.T) {
// enable limit correctly // enable limit correctly
ch.ParseModes("+l", "256") ch.ParseModes("+l", "256")
m.CheckNothingWritten(t) m.ExpectNothing()
if md.Limit != 256 { if md.Limit != 256 {
t.Errorf("Limit for channel not set correctly") t.Errorf("Limit for channel not set correctly")
} }
// enable limit incorrectly // enable limit incorrectly
ch.ParseModes("+l") ch.ParseModes("+l")
m.CheckWrittenAtLevel(t, logging.Warn, m.ExpectAt(logging.Warn,
"Channel.ParseModes(): not enough arguments to process MODE #test1 +l") "Channel.ParseModes(): not enough arguments to process MODE #test1 +l")
if md.Limit != 256 { if md.Limit != 256 {
t.Errorf("Bad limit value caused limit to be unset.") t.Errorf("Bad limit value caused limit to be unset.")
@ -117,7 +115,7 @@ func TestChannelParseModes(t *testing.T) {
// disable limit correctly // disable limit correctly
ch.ParseModes("-l") ch.ParseModes("-l")
m.CheckNothingWritten(t) m.ExpectNothing()
if md.Limit != 0 { if md.Limit != 0 {
t.Errorf("Limit for channel not unset correctly") t.Errorf("Limit for channel not unset correctly")
} }
@ -129,14 +127,14 @@ func TestChannelParseModes(t *testing.T) {
// enable key correctly // enable key correctly
ch.ParseModes("+k", "foobar") ch.ParseModes("+k", "foobar")
m.CheckNothingWritten(t) m.ExpectNothing()
if md.Key != "foobar" { if md.Key != "foobar" {
t.Errorf("Key for channel not set correctly") t.Errorf("Key for channel not set correctly")
} }
// enable key incorrectly // enable key incorrectly
ch.ParseModes("+k") ch.ParseModes("+k")
m.CheckWrittenAtLevel(t, logging.Warn, m.ExpectAt(logging.Warn,
"Channel.ParseModes(): not enough arguments to process MODE #test1 +k") "Channel.ParseModes(): not enough arguments to process MODE #test1 +k")
if md.Key != "foobar" { if md.Key != "foobar" {
t.Errorf("Bad key value caused key to be unset.") t.Errorf("Bad key value caused key to be unset.")
@ -144,7 +142,7 @@ func TestChannelParseModes(t *testing.T) {
// disable key correctly // disable key correctly
ch.ParseModes("-k") ch.ParseModes("-k")
m.CheckNothingWritten(t) m.ExpectNothing()
if md.Key != "" { if md.Key != "" {
t.Errorf("Key for channel not unset correctly") t.Errorf("Key for channel not unset correctly")
} }
@ -153,24 +151,24 @@ func TestChannelParseModes(t *testing.T) {
cp.Op = true cp.Op = true
cp.HalfOp = true cp.HalfOp = true
ch.ParseModes("+aq-o", "test1", "test1", "test1") ch.ParseModes("+aq-o", "test1", "test1", "test1")
m.CheckNothingWritten(t) m.ExpectNothing()
if !cp.Owner || !cp.Admin || cp.Op || !cp.HalfOp || cp.Voice { if !cp.Owner || !cp.Admin || cp.Op || !cp.HalfOp || cp.Voice {
t.Errorf("Channel privileges not flipped correctly by ParseModes.") t.Errorf("Channel privileges not flipped correctly by ParseModes.")
} }
ch.ParseModes("+v", "test2") ch.ParseModes("+v", "test2")
m.CheckWrittenAtLevel(t, logging.Warn, m.ExpectAt(logging.Warn,
"Channel.ParseModes(): untracked nick test2 received MODE on channel #test1") "Channel.ParseModes(): untracked nick test2 received MODE on channel #test1")
ch.ParseModes("-v") ch.ParseModes("-v")
m.CheckWrittenAtLevel(t, logging.Warn, m.ExpectAt(logging.Warn,
"Channel.ParseModes(): not enough arguments to process MODE #test1 -v") "Channel.ParseModes(): not enough arguments to process MODE #test1 -v")
// Test a random mix of modes, just to be sure // Test a random mix of modes, just to be sure
md.Limit = 256 md.Limit = 256
ch.ParseModes("+zpt-qsl+kv-h", "test1", "foobar", "test1") ch.ParseModes("+zpt-qsl+kv-h", "test1", "foobar", "test1")
m.CheckWrittenAtLevel(t, logging.Warn, m.ExpectAt(logging.Warn,
"Channel.ParseModes(): not enough arguments to process MODE #test1 -h") "Channel.ParseModes(): not enough arguments to process MODE #test1 -h")
if !md.Private || md.Secret || !md.ProtectedTopic || !md.NoExternalMsg || if !md.Private || md.Secret || !md.ProtectedTopic || !md.NoExternalMsg ||
@ -187,6 +185,5 @@ func TestChannelParseModes(t *testing.T) {
// Finally, check we get an info log for an unrecognised mode character // Finally, check we get an info log for an unrecognised mode character
ch.ParseModes("+d") ch.ParseModes("+d")
m.CheckWrittenAtLevel(t, logging.Info, m.ExpectAt(logging.Info, "Channel.ParseModes(): unknown mode char d")
"Channel.ParseModes(): unknown mode char d")
} }

View File

@ -6,7 +6,7 @@ import (
) )
func TestNewNick(t *testing.T) { func TestNewNick(t *testing.T) {
l, _ := logging.NewMock() l, _ := logging.NewMock(t)
nk := NewNick("test1", l) nk := NewNick("test1", l)
if nk.Nick != "test1" || nk.l != l { if nk.Nick != "test1" || nk.l != l {
@ -18,13 +18,13 @@ func TestNewNick(t *testing.T) {
} }
func TestAddChannel(t *testing.T) { func TestAddChannel(t *testing.T) {
l, m := logging.NewMock() l, m := logging.NewMock(t)
nk := NewNick("test1", l) nk := NewNick("test1", l)
ch := NewChannel("#test1", l) ch := NewChannel("#test1", l)
cp := new(ChanPrivs) cp := new(ChanPrivs)
nk.addChannel(ch, cp) nk.addChannel(ch, cp)
m.CheckNothingWritten(t) m.ExpectNothing()
if len(nk.chans) != 1 || len(nk.lookup) != 1 { if len(nk.chans) != 1 || len(nk.lookup) != 1 {
t.Errorf("Channel lists not updated correctly for add.") t.Errorf("Channel lists not updated correctly for add.")
@ -37,20 +37,18 @@ func TestAddChannel(t *testing.T) {
} }
nk.addChannel(ch, cp) nk.addChannel(ch, cp)
m.CheckWrittenAtLevel(t, logging.Warn, m.ExpectAt(logging.Warn, "Nick.addChannel(): test1 already on #test1.")
"Nick.addChannel(): test1 already on #test1.")
} }
func TestDelChannel(t *testing.T) { func TestDelChannel(t *testing.T) {
l, m := logging.NewMock() l, m := logging.NewMock(t)
nk := NewNick("test1", l) nk := NewNick("test1", l)
ch := NewChannel("#test1", l) ch := NewChannel("#test1", l)
cp := new(ChanPrivs) cp := new(ChanPrivs)
// Testing the error state first is easier // Testing the error state first is easier
nk.delChannel(ch) nk.delChannel(ch)
m.CheckWrittenAtLevel(t, logging.Warn, m.ExpectAt(logging.Warn, "Nick.delChannel(): test1 not on #test1.")
"Nick.delChannel(): test1 not on #test1.")
nk.addChannel(ch, cp) nk.addChannel(ch, cp)
nk.delChannel(ch) nk.delChannel(ch)
@ -66,7 +64,7 @@ func TestDelChannel(t *testing.T) {
} }
func TestNickParseModes(t *testing.T) { func TestNickParseModes(t *testing.T) {
l, m := logging.NewMock() l, m := logging.NewMock(t)
nk := NewNick("test1", l) nk := NewNick("test1", l)
md := nk.Modes md := nk.Modes
@ -81,7 +79,7 @@ func TestNickParseModes(t *testing.T) {
// Parse a mode line that flips one true to false and two false to true // Parse a mode line that flips one true to false and two false to true
nk.ParseModes("+z-x+w") nk.ParseModes("+z-x+w")
m.CheckNothingWritten(t) m.ExpectNothing()
if !md.Invisible || md.Oper || !md.WallOps || md.HiddenHost || !md.SSL { if !md.Invisible || md.Oper || !md.WallOps || md.HiddenHost || !md.SSL {
t.Errorf("Modes not flipped correctly by ParseModes.") t.Errorf("Modes not flipped correctly by ParseModes.")
@ -89,6 +87,5 @@ func TestNickParseModes(t *testing.T) {
// Check that passing an unknown mode char results in an info log // Check that passing an unknown mode char results in an info log
nk.ParseModes("+d") nk.ParseModes("+d")
m.CheckWrittenAtLevel(t, logging.Info, m.ExpectAt(logging.Info, "Nick.ParseModes(): unknown mode char d")
"Nick.ParseModes(): unknown mode char d")
} }

View File

@ -6,10 +6,10 @@ import (
) )
func TestSTNewTracker(t *testing.T) { func TestSTNewTracker(t *testing.T) {
l, m := logging.NewMock() l, m := logging.NewMock(t)
st := NewTracker("mynick", l) st := NewTracker("mynick", l)
m.CheckNothingWritten(t) m.ExpectNothing()
if st.l != l { if st.l != l {
t.Errorf("State tracker's logger not set correctly.") t.Errorf("State tracker's logger not set correctly.")
@ -26,11 +26,11 @@ func TestSTNewTracker(t *testing.T) {
} }
func TestSTNewNick(t *testing.T) { func TestSTNewNick(t *testing.T) {
l, m := logging.NewMock() l, m := logging.NewMock(t)
st := NewTracker("mynick", l) st := NewTracker("mynick", l)
test1 := st.NewNick("test1") test1 := st.NewNick("test1")
m.CheckNothingWritten(t) m.ExpectNothing()
if test1 == nil || test1.Nick != "test1" || test1.l != l { if test1 == nil || test1.Nick != "test1" || test1.l != l {
t.Errorf("Nick object created incorrectly by NewNick.") t.Errorf("Nick object created incorrectly by NewNick.")
@ -42,12 +42,11 @@ func TestSTNewNick(t *testing.T) {
if fail := st.NewNick("test1"); fail != nil { if fail := st.NewNick("test1"); fail != nil {
t.Errorf("Creating duplicate nick did not produce nil return.") t.Errorf("Creating duplicate nick did not produce nil return.")
} }
m.CheckWrittenAtLevel(t, logging.Warn, m.ExpectAt(logging.Warn, "StateTracker.NewNick(): test1 already tracked.")
"StateTracker.NewNick(): test1 already tracked.")
} }
func TestSTGetNick(t *testing.T) { func TestSTGetNick(t *testing.T) {
l, _ := logging.NewMock() l, _ := logging.NewMock(t)
st := NewTracker("mynick", l) st := NewTracker("mynick", l)
test1 := NewNick("test1", l) test1 := NewNick("test1", l)
@ -65,7 +64,7 @@ func TestSTGetNick(t *testing.T) {
} }
func TestSTReNick(t *testing.T) { func TestSTReNick(t *testing.T) {
l, m := logging.NewMock() l, m := logging.NewMock(t)
st := NewTracker("mynick", l) st := NewTracker("mynick", l)
test1 := NewNick("test1", l) test1 := NewNick("test1", l)
@ -78,7 +77,7 @@ func TestSTReNick(t *testing.T) {
chan1.addNick(test1, cp) chan1.addNick(test1, cp)
st.ReNick("test1", "test2") st.ReNick("test1", "test2")
m.CheckNothingWritten(t) m.ExpectNothing()
if _, ok := st.nicks["test1"]; ok { if _, ok := st.nicks["test1"]; ok {
t.Errorf("Nick test1 still exists after ReNick.") t.Errorf("Nick test1 still exists after ReNick.")
@ -103,8 +102,7 @@ func TestSTReNick(t *testing.T) {
st.nicks["test1"] = test2 st.nicks["test1"] = test2
st.ReNick("test1", "test2") st.ReNick("test1", "test2")
m.CheckWrittenAtLevel(t, logging.Warn, m.ExpectAt(logging.Warn, "StateTracker.ReNick(): test2 already exists.")
"StateTracker.ReNick(): test2 already exists.")
if n, ok := st.nicks["test2"]; !ok || n != test1 { if n, ok := st.nicks["test2"]; !ok || n != test1 {
t.Errorf("Nick test2 overwritten/deleted by ReNick.") t.Errorf("Nick test2 overwritten/deleted by ReNick.")
@ -117,19 +115,18 @@ func TestSTReNick(t *testing.T) {
} }
st.ReNick("test3", "test2") st.ReNick("test3", "test2")
m.CheckWrittenAtLevel(t, logging.Warn, m.ExpectAt(logging.Warn, "StateTracker.ReNick(): test3 not tracked.")
"StateTracker.ReNick(): test3 not tracked.")
} }
func TestSTDelNick(t *testing.T) { func TestSTDelNick(t *testing.T) {
l, m := logging.NewMock() l, m := logging.NewMock(t)
st := NewTracker("mynick", l) st := NewTracker("mynick", l)
nick1 := NewNick("test1", l) nick1 := NewNick("test1", l)
st.nicks["test1"] = nick1 st.nicks["test1"] = nick1
st.DelNick("test1") st.DelNick("test1")
m.CheckNothingWritten(t) m.ExpectNothing()
if _, ok := st.nicks["test1"]; ok { if _, ok := st.nicks["test1"]; ok {
t.Errorf("Nick test1 still exists after DelNick.") t.Errorf("Nick test1 still exists after DelNick.")
@ -141,8 +138,7 @@ func TestSTDelNick(t *testing.T) {
st.nicks["test1"] = nick1 st.nicks["test1"] = nick1
st.DelNick("test2") st.DelNick("test2")
m.CheckWrittenAtLevel(t, logging.Warn, m.ExpectAt(logging.Warn, "StateTracker.DelNick(): test2 not tracked.")
"StateTracker.DelNick(): test2 not tracked.")
if len(st.nicks) != 2 { if len(st.nicks) != 2 {
t.Errorf("Deleting unknown nick had unexpected side-effects.") t.Errorf("Deleting unknown nick had unexpected side-effects.")
@ -150,8 +146,7 @@ func TestSTDelNick(t *testing.T) {
// Deleting my nick shouldn't work // Deleting my nick shouldn't work
st.DelNick("mynick") st.DelNick("mynick")
m.CheckWrittenAtLevel(t, logging.Warn, m.ExpectAt(logging.Warn, "StateTracker.DelNick(): won't delete myself.")
"StateTracker.DelNick(): won't delete myself.")
if len(st.nicks) != 2 { if len(st.nicks) != 2 {
t.Errorf("Deleting myself had unexpected side-effects.") t.Errorf("Deleting myself had unexpected side-effects.")
@ -181,7 +176,7 @@ func TestSTDelNick(t *testing.T) {
} }
st.DelNick("test1") st.DelNick("test1")
m.CheckNothingWritten(t) m.ExpectNothing()
// Actual deletion tested above... // Actual deletion tested above...
if len(chan1.nicks) != 1 || len(st.chans) != 1 || if len(chan1.nicks) != 1 || len(st.chans) != 1 ||
@ -198,7 +193,7 @@ func TestSTDelNick(t *testing.T) {
} }
func TestSTNewChannel(t *testing.T) { func TestSTNewChannel(t *testing.T) {
l, m := logging.NewMock() l, m := logging.NewMock(t)
st := NewTracker("mynick", l) st := NewTracker("mynick", l)
if len(st.chans) != 0 { if len(st.chans) != 0 {
@ -206,7 +201,7 @@ func TestSTNewChannel(t *testing.T) {
} }
test1 := st.NewChannel("#test1") test1 := st.NewChannel("#test1")
m.CheckNothingWritten(t) m.ExpectNothing()
if test1 == nil || test1.Name != "#test1" || test1.l != l { if test1 == nil || test1.Name != "#test1" || test1.l != l {
t.Errorf("Channel object created incorrectly by NewChannel.") t.Errorf("Channel object created incorrectly by NewChannel.")
@ -218,12 +213,11 @@ func TestSTNewChannel(t *testing.T) {
if fail := st.NewChannel("#test1"); fail != nil { if fail := st.NewChannel("#test1"); fail != nil {
t.Errorf("Creating duplicate chan did not produce nil return.") t.Errorf("Creating duplicate chan did not produce nil return.")
} }
m.CheckWrittenAtLevel(t, logging.Warn, m.ExpectAt(logging.Warn, "StateTracker.NewChannel(): #test1 already tracked.")
"StateTracker.NewChannel(): #test1 already tracked.")
} }
func TestSTGetChannel(t *testing.T) { func TestSTGetChannel(t *testing.T) {
l, _ := logging.NewMock() l, _ := logging.NewMock(t)
st := NewTracker("mynick", l) st := NewTracker("mynick", l)
test1 := NewChannel("#test1", l) test1 := NewChannel("#test1", l)
@ -241,14 +235,14 @@ func TestSTGetChannel(t *testing.T) {
} }
func TestSTDelChannel(t *testing.T) { func TestSTDelChannel(t *testing.T) {
l, m := logging.NewMock() l, m := logging.NewMock(t)
st := NewTracker("mynick", l) st := NewTracker("mynick", l)
chan1 := NewChannel("#test1", l) chan1 := NewChannel("#test1", l)
st.chans["#test1"] = chan1 st.chans["#test1"] = chan1
st.DelChannel("#test1") st.DelChannel("#test1")
m.CheckNothingWritten(t) m.ExpectNothing()
if _, ok := st.chans["#test1"]; ok { if _, ok := st.chans["#test1"]; ok {
t.Errorf("Channel test1 still exists after DelChannel.") t.Errorf("Channel test1 still exists after DelChannel.")
@ -260,8 +254,7 @@ func TestSTDelChannel(t *testing.T) {
st.chans["#test1"] = chan1 st.chans["#test1"] = chan1
st.DelChannel("#test2") st.DelChannel("#test2")
m.CheckWrittenAtLevel(t, logging.Warn, m.ExpectAt(logging.Warn, "StateTracker.DelChannel(): #test2 not tracked.")
"StateTracker.DelChannel(): #test2 not tracked.")
if len(st.chans) != 1 { if len(st.chans) != 1 {
t.Errorf("DelChannel had unexpected side-effects.") t.Errorf("DelChannel had unexpected side-effects.")
@ -294,7 +287,7 @@ func TestSTDelChannel(t *testing.T) {
} }
st.DelChannel("#test1") st.DelChannel("#test1")
m.CheckNothingWritten(t) m.ExpectNothing()
// Test intermediate state. We're still on #test2 with test1, so test1 // Test intermediate state. We're still on #test2 with test1, so test1
// shouldn't be deleted from state tracking itself just yet. // shouldn't be deleted from state tracking itself just yet.
@ -311,7 +304,7 @@ func TestSTDelChannel(t *testing.T) {
} }
st.DelChannel("#test2") st.DelChannel("#test2")
m.CheckNothingWritten(t) m.ExpectNothing()
// Test final state. Deleting #test2 means that we're no longer on any // Test final state. Deleting #test2 means that we're no longer on any
// common channels with test1, and thus it should be removed from tracking. // common channels with test1, and thus it should be removed from tracking.
@ -329,7 +322,7 @@ func TestSTDelChannel(t *testing.T) {
} }
func TestSTIsOn(t *testing.T) { func TestSTIsOn(t *testing.T) {
l, m := logging.NewMock() l, m := logging.NewMock(t)
st := NewTracker("mynick", l) st := NewTracker("mynick", l)
nick1 := NewNick("test1", l) nick1 := NewNick("test1", l)
@ -346,50 +339,45 @@ func TestSTIsOn(t *testing.T) {
if priv, ok := st.IsOn("#test1", "test1"); !ok || priv != cp { if priv, ok := st.IsOn("#test1", "test1"); !ok || priv != cp {
t.Errorf("test1 is on #test1 (now)") t.Errorf("test1 is on #test1 (now)")
} }
m.CheckNothingWritten(t) m.ExpectNothing()
} }
func TestSTAssociate(t *testing.T) { func TestSTAssociate(t *testing.T) {
l, m := logging.NewMock() l, m := logging.NewMock(t)
st := NewTracker("mynick", l) st := NewTracker("mynick", l)
nick1 := st.NewNick("test1") nick1 := st.NewNick("test1")
chan1 := st.NewChannel("#test1") chan1 := st.NewChannel("#test1")
cp := st.Associate(chan1, nick1) cp := st.Associate(chan1, nick1)
m.CheckNothingWritten(t) m.ExpectNothing()
if priv, ok := st.IsOn("#test1", "test1"); !ok || cp != priv { if priv, ok := st.IsOn("#test1", "test1"); !ok || cp != priv {
t.Errorf("test1 was not associated with #test1.") t.Errorf("test1 was not associated with #test1.")
} }
// Test error cases // Test error cases
st.Associate(nil, nick1) st.Associate(nil, nick1)
m.CheckWrittenAtLevel(t, logging.Error, m.ExpectAt(logging.Error, "StateTracker.Associate(): passed nil values :-(")
"StateTracker.Associate(): passed nil values :-(")
st.Associate(chan1, nil) st.Associate(chan1, nil)
m.CheckWrittenAtLevel(t, logging.Error, m.ExpectAt(logging.Error, "StateTracker.Associate(): passed nil values :-(")
"StateTracker.Associate(): passed nil values :-(")
st.Associate(chan1, nick1) st.Associate(chan1, nick1)
m.CheckWrittenAtLevel(t, logging.Warn, m.ExpectAt(logging.Warn, "StateTracker.Associate(): test1 already on #test1.")
"StateTracker.Associate(): test1 already on #test1.")
nick2 := NewNick("test2", l) nick2 := NewNick("test2", l)
st.Associate(chan1, nick2) st.Associate(chan1, nick2)
m.CheckWrittenAtLevel(t, logging.Error, m.ExpectAt(logging.Error, "StateTracker.Associate(): nick test2 not found "+
"StateTracker.Associate(): nick test2 not found in (or differs from) "+ "in (or differs from) internal state.")
"internal state.")
chan2 := NewChannel("#test2", l) chan2 := NewChannel("#test2", l)
st.Associate(chan2, nick1) st.Associate(chan2, nick1)
m.CheckWrittenAtLevel(t, logging.Error, m.ExpectAt(logging.Error, "StateTracker.Associate(): channel #test2 not "+
"StateTracker.Associate(): channel #test2 not found in (or differs "+ "found in (or differs from) internal state.")
"from) internal state.")
} }
func TestSTDissociate(t *testing.T) { func TestSTDissociate(t *testing.T) {
l, m := logging.NewMock() l, m := logging.NewMock(t)
st := NewTracker("mynick", l) st := NewTracker("mynick", l)
nick1 := st.NewNick("test1") nick1 := st.NewNick("test1")
@ -410,7 +398,7 @@ func TestSTDissociate(t *testing.T) {
// First, test the case of me leaving #test2 // First, test the case of me leaving #test2
st.Dissociate(chan2, st.me) st.Dissociate(chan2, st.me)
m.CheckNothingWritten(t) m.ExpectNothing()
// This should have resulted in the complete deletion of the channel. // This should have resulted in the complete deletion of the channel.
if len(chan1.nicks) != 2 || len(chan2.nicks) != 0 || len(st.nicks) != 2 || if len(chan1.nicks) != 2 || len(chan2.nicks) != 0 || len(st.nicks) != 2 ||
@ -422,7 +410,7 @@ func TestSTDissociate(t *testing.T) {
chan2 = st.NewChannel("#test2") chan2 = st.NewChannel("#test2")
st.Associate(chan2, st.me) st.Associate(chan2, st.me)
st.Associate(chan2, nick1) st.Associate(chan2, nick1)
m.CheckNothingWritten(t) m.ExpectNothing()
// Check state once moar. // Check state once moar.
if len(chan1.nicks) != 2 || len(chan2.nicks) != 2 || len(st.nicks) != 2 || if len(chan1.nicks) != 2 || len(chan2.nicks) != 2 || len(st.nicks) != 2 ||
@ -433,7 +421,7 @@ func TestSTDissociate(t *testing.T) {
// Now, lets dissociate test1 from #test1 then #test2. // Now, lets dissociate test1 from #test1 then #test2.
// This first one should only result in a change in associations. // This first one should only result in a change in associations.
st.Dissociate(chan1, nick1) st.Dissociate(chan1, nick1)
m.CheckNothingWritten(t) m.ExpectNothing()
if len(chan1.nicks) != 1 || len(chan2.nicks) != 2 || len(st.nicks) != 2 || if len(chan1.nicks) != 1 || len(chan2.nicks) != 2 || len(st.nicks) != 2 ||
len(st.me.chans) != 2 || len(nick1.chans) != 1 || len(st.chans) != 2 { len(st.me.chans) != 2 || len(nick1.chans) != 1 || len(st.chans) != 2 {
@ -443,7 +431,7 @@ func TestSTDissociate(t *testing.T) {
// This second one should also delete test1 // This second one should also delete test1
// as it's no longer on any common channels with us // as it's no longer on any common channels with us
st.Dissociate(chan2, nick1) st.Dissociate(chan2, nick1)
m.CheckNothingWritten(t) m.ExpectNothing()
if len(chan1.nicks) != 1 || len(chan2.nicks) != 1 || len(st.nicks) != 1 || if len(chan1.nicks) != 1 || len(chan2.nicks) != 1 || len(st.nicks) != 1 ||
len(st.me.chans) != 2 || len(nick1.chans) != 0 || len(st.chans) != 2 { len(st.me.chans) != 2 || len(nick1.chans) != 0 || len(st.chans) != 2 {
@ -454,32 +442,27 @@ func TestSTDissociate(t *testing.T) {
// test1 was deleted above, so "re-track" it for this test. // test1 was deleted above, so "re-track" it for this test.
nick1 = st.NewNick("test1") nick1 = st.NewNick("test1")
st.Dissociate(chan1, nick1) st.Dissociate(chan1, nick1)
m.CheckWrittenAtLevel(t, logging.Warn, m.ExpectAt(logging.Warn, "StateTracker.Dissociate(): test1 not on #test1.")
"StateTracker.Dissociate(): test1 not on #test1.")
st.Dissociate(chan1, nil) st.Dissociate(chan1, nil)
m.CheckWrittenAtLevel(t, logging.Error, m.ExpectAt(logging.Error, "StateTracker.Dissociate(): passed nil values :-(")
"StateTracker.Dissociate(): passed nil values :-(")
st.Dissociate(nil, nick1) st.Dissociate(nil, nick1)
m.CheckWrittenAtLevel(t, logging.Error, m.ExpectAt(logging.Error, "StateTracker.Dissociate(): passed nil values :-(")
"StateTracker.Dissociate(): passed nil values :-(")
nick3 := NewNick("test3", l) nick3 := NewNick("test3", l)
st.Dissociate(chan1, nick3) st.Dissociate(chan1, nick3)
m.CheckWrittenAtLevel(t, logging.Error, m.ExpectAt(logging.Error, "StateTracker.Dissociate(): nick test3 not "+
"StateTracker.Dissociate(): nick test3 not found in (or differs from) "+ "found in (or differs from) internal state.")
"internal state.")
chan3 := NewChannel("#test3", l) chan3 := NewChannel("#test3", l)
st.Dissociate(chan3, nick1) st.Dissociate(chan3, nick1)
m.CheckWrittenAtLevel(t, logging.Error, m.ExpectAt(logging.Error, "StateTracker.Dissociate(): channel #test3 not "+
"StateTracker.Dissociate(): channel #test3 not found in (or differs "+ "found in (or differs from) internal state.")
"from) internal state.")
} }
func TestSTWipe(t *testing.T) { func TestSTWipe(t *testing.T) {
l, m := logging.NewMock() l, m := logging.NewMock(t)
st := NewTracker("mynick", l) st := NewTracker("mynick", l)
nick1 := st.NewNick("test1") nick1 := st.NewNick("test1")
@ -504,7 +487,7 @@ func TestSTWipe(t *testing.T) {
st.Associate(chan1, nick3) st.Associate(chan1, nick3)
m.CheckNothingWritten(t) m.ExpectNothing()
// Check the state we have at this point is what we would expect. // Check the state we have at this point is what we would expect.
if len(st.nicks) != 4 || len(st.chans) != 3 || len(st.me.chans) != 3 { if len(st.nicks) != 4 || len(st.chans) != 3 || len(st.me.chans) != 3 {
@ -519,7 +502,7 @@ func TestSTWipe(t *testing.T) {
// Nuke *all* the state! // Nuke *all* the state!
st.Wipe() st.Wipe()
m.CheckNothingWritten(t) m.ExpectNothing()
// Check the state we have at this point is what we would expect. // Check the state we have at this point is what we would expect.
if len(st.nicks) != 1 || len(st.chans) != 0 || len(st.me.chans) != 0 { if len(st.nicks) != 1 || len(st.chans) != 0 || len(st.me.chans) != 0 {