Epic refactor of the refactor.

This commit is contained in:
Alex Bramley 2011-10-20 00:10:33 +01:00
parent 7f6e5fc7d9
commit 111a23d87c
4 changed files with 204 additions and 150 deletions

View File

@ -11,8 +11,8 @@ import (
type Channel struct { type Channel struct {
Name, Topic string Name, Topic string
Modes *ChanMode Modes *ChanMode
lookup map[string]*Nick
nicks map[*Nick]*ChanPrivs nicks map[*Nick]*ChanPrivs
st StateTracker
} }
// A struct representing the modes of an IRC Channel // A struct representing the modes of an IRC Channel
@ -95,50 +95,35 @@ func NewChannel(name string) *Channel {
Name: name, Name: name,
Modes: new(ChanMode), Modes: new(ChanMode),
nicks: make(map[*Nick]*ChanPrivs), nicks: make(map[*Nick]*ChanPrivs),
} lookup: make(map[string]*Nick),
}
// Associates a Nick with a Channel using a shared set of ChanPrivs
func (ch *Channel) AddNick(n *Nick) {
if _, ok := ch.nicks[n]; !ok {
ch.nicks[n] = new(ChanPrivs)
n.chans[ch] = ch.nicks[n]
} else {
logging.Warn("Channel.AddNick(): trying to add already-present "+
"nick %s to channel %s", n.Nick, ch.Name)
} }
} }
// Returns true if the Nick is associated with the Channel // Returns true if the Nick is associated with the Channel
func (ch *Channel) IsOn(n *Nick) bool { func (ch *Channel) IsOn(nk *Nick) bool {
_, ok := ch.nicks[n] _, ok := ch.nicks[nk]
return ok return ok
} }
// Disassociates a Nick from a Channel. Will call ch.Delete() if the Nick being func (ch *Channel) IsOnStr(n string) bool {
// removed is the connection's nick. Will also call n.DelChannel(ch) to remove _, ok := ch.lookup[n]
// the association from the perspective of the Nick. return ok
func (ch *Channel) DelNick(n *Nick) {
if _, ok := ch.nicks[n]; ok {
if n.me {
// we're leaving the channel, so remove all state we have about it
ch.Delete()
} else {
ch.nicks[n] = nil, false
n.DelChannel(ch)
}
}
// we call Channel.DelNick() and Nick.DelChannel() from each other to ensure
// consistency, and this would mean spewing an error message every delete
} }
// Stops the Channel from being tracked by state tracking handlers. Also calls // Associates a Nick with a Channel
// n.DelChannel(ch) for all nicks that are associated with the channel. func (ch *Channel) addNick(nk *Nick, cp *ChanPrivs) {
func (ch *Channel) Delete() { if _, ok := ch.nicks[nk]; !ok {
for n, _ := range ch.nicks { ch.nicks[nk] = cp
n.DelChannel(ch) ch.lookup[nk.Nick] = nk
}
}
// Disassociates a Nick from a Channel.
func (ch *Channel) delNick(nk *Nick) {
if _, ok := ch.nicks[nk]; ok {
ch.nicks[nk] = nil, false
ch.lookup[nk.Nick] = nil, false
} }
ch.st.DelChannel(ch.Name)
} }
// Parses mode strings for a channel. // Parses mode strings for a channel.
@ -190,19 +175,19 @@ func (ch *Channel) ParseModes(modes string, modeargs []string) {
} }
case 'q', 'a', 'o', 'h', 'v': case 'q', 'a', 'o', 'h', 'v':
if len(modeargs) != 0 { if len(modeargs) != 0 {
n := ch.st.GetNick(modeargs[0]) if nk, ok := ch.lookup[modeargs[0]]; ok {
if p, ok := ch.nicks[n]; ok { cp := ch.nicks[nk]
switch m { switch m {
case 'q': case 'q':
p.Owner = modeop cp.Owner = modeop
case 'a': case 'a':
p.Admin = modeop cp.Admin = modeop
case 'o': case 'o':
p.Op = modeop cp.Op = modeop
case 'h': case 'h':
p.HalfOp = modeop cp.HalfOp = modeop
case 'v': case 'v':
p.Voice = modeop cp.Voice = modeop
} }
modeargs = modeargs[1:] modeargs = modeargs[1:]
} else { } else {
@ -229,8 +214,8 @@ func (ch *Channel) String() string {
str += "Topic: " + ch.Topic + "\n\t" str += "Topic: " + ch.Topic + "\n\t"
str += "Modes: " + ch.Modes.String() + "\n\t" str += "Modes: " + ch.Modes.String() + "\n\t"
str += "Nicks: \n" str += "Nicks: \n"
for n, p := range ch.nicks { for nk, cp := range ch.nicks {
str += "\t\t" + n.Nick + ": " + p.String() + "\n" str += "\t\t" + nk.Nick + ": " + cp.String() + "\n"
} }
return str return str
} }
@ -273,9 +258,9 @@ func (cm *ChanMode) String() string {
// Returns a string representing the channel privileges. Looks like: // Returns a string representing the channel privileges. Looks like:
// +o // +o
func (p *ChanPrivs) String() string { func (cp *ChanPrivs) String() string {
str := "+" str := "+"
v := reflect.Indirect(reflect.ValueOf(p)) v := reflect.Indirect(reflect.ValueOf(cp))
t := v.Type() t := v.Type()
for i := 0; i < v.NumField(); i++ { for i := 0; i < v.NumField(); i++ {
switch f := v.Field(i); f.Kind() { switch f := v.Field(i); f.Kind() {

View File

@ -9,9 +9,8 @@ import (
type Nick struct { type Nick struct {
Nick, Ident, Host, Name string Nick, Ident, Host, Name string
Modes *NickMode Modes *NickMode
lookup map[string]*Channel
chans map[*Channel]*ChanPrivs chans map[*Channel]*ChanPrivs
me bool
st StateTracker
} }
// A struct representing the modes of an IRC Nick (User Modes) // A struct representing the modes of an IRC Nick (User Modes)
@ -44,68 +43,44 @@ func init() {
* Nick methods for state management * Nick methods for state management
\******************************************************************************/ \******************************************************************************/
func NewNick(nick string) *Nick { func NewNick(n string) *Nick {
return &Nick{ return &Nick{
Nick: nick, Nick: n,
Modes: new(NickMode), Modes: new(NickMode),
chans: make(map[*Channel]*ChanPrivs), chans: make(map[*Channel]*ChanPrivs),
} lookup: make(map[string]*Channel),
}
// Associates a Channel with a Nick using a shared ChanPrivs
//
// Very slightly different to Channel.AddNick() in that it tests for a
// pre-existing association within the Nick object rather than the
// Channel object before associating the two.
func (n *Nick) AddChannel(ch *Channel) {
if _, ok := n.chans[ch]; !ok {
ch.nicks[n] = new(ChanPrivs)
n.chans[ch] = ch.nicks[n]
} else {
logging.Warn("Nick.AddChannel(): trying to add already-present "+
"channel %s to nick %s", ch.Name, n.Nick)
} }
} }
// Returns true if the Nick is associated with the Channel. // Returns true if the Nick is associated with the Channel.
func (n *Nick) IsOn(ch *Channel) bool { func (nk *Nick) IsOn(ch *Channel) bool {
_, ok := n.chans[ch] _, ok := nk.chans[ch]
return ok return ok
} }
// Returns true if the Nick is Me! func (nk *Nick) IsOnStr(c string) bool {
func (n *Nick) IsMe() bool { _, ok := nk.lookup[c]
return n.me return ok
} }
// Disassociates a Channel from a Nick. Will call n.Delete() if the Nick is no // Associates a Channel with a Nick.
// longer on any channels we are tracking. Will also call ch.DelNick(n) to func (nk *Nick) addChannel(ch *Channel, cp *ChanPrivs) {
// remove the association from the perspective of the Channel. if _, ok := nk.chans[ch]; !ok {
func (n *Nick) DelChannel(ch *Channel) { nk.chans[ch] = cp
if _, ok := n.chans[ch]; ok { nk.lookup[ch.Name] = ch
n.chans[ch] = nil, false
ch.DelNick(n)
if len(n.chans) == 0 {
// nick is no longer in any channels we inhabit, stop tracking it
n.Delete()
}
} }
} }
// Stops the Nick from being tracked by state tracking handlers. Also calls // Disassociates a Channel from a Nick.
// ch.DelNick(n) for all Nicks that are associated with the Channel. func (nk *Nick) delChannel(ch *Channel) {
func (n *Nick) Delete() { if _, ok := nk.chans[ch]; ok {
// we don't ever want to remove *our* nick from st.nicks... nk.chans[ch] = nil, false
if !n.me { nk.lookup[ch.Name] = nil, false
for ch, _ := range n.chans {
ch.DelNick(n)
}
n.st.DelNick(n.Nick)
} }
} }
// Parse mode strings for a Nick. // Parse mode strings for a Nick.
func (n *Nick) ParseModes(modes string) { func (nk *Nick) ParseModes(modes string) {
var modeop bool // true => add mode, false => remove mode var modeop bool // true => add mode, false => remove mode
for i := 0; i < len(modes); i++ { for i := 0; i < len(modes); i++ {
switch m := modes[i]; m { switch m := modes[i]; m {
@ -114,15 +89,17 @@ func (n *Nick) ParseModes(modes string) {
case '-': case '-':
modeop = false modeop = false
case 'i': case 'i':
n.Modes.Invisible = modeop nk.Modes.Invisible = modeop
case 'o': case 'o':
n.Modes.Oper = modeop nk.Modes.Oper = modeop
case 'w': case 'w':
n.Modes.WallOps = modeop nk.Modes.WallOps = modeop
case 'x': case 'x':
n.Modes.HiddenHost = modeop nk.Modes.HiddenHost = modeop
case 'z': case 'z':
n.Modes.SSL = modeop nk.Modes.SSL = modeop
default:
logging.Info("Nick.ParseModes(): unknown mode char %c", m)
} }
} }
} }
@ -135,17 +112,14 @@ func (n *Nick) ParseModes(modes string) {
// Channels: // Channels:
// <channel>: <privs> e.g. #moo: +o // <channel>: <privs> e.g. #moo: +o
// ... // ...
func (n *Nick) String() string { func (nk *Nick) String() string {
str := "Nick: " + n.Nick + "\n\t" str := "Nick: " + nk.Nick + "\n\t"
str += "Hostmask: " + n.Ident + "@" + n.Host + "\n\t" str += "Hostmask: " + nk.Ident + "@" + nk.Host + "\n\t"
str += "Real Name: " + n.Name + "\n\t" str += "Real Name: " + nk.Name + "\n\t"
str += "Modes: " + n.Modes.String() + "\n\t" str += "Modes: " + nk.Modes.String() + "\n\t"
if n.me {
str += "I think this is ME!\n\t"
}
str += "Channels: \n" str += "Channels: \n"
for ch, p := range n.chans { for ch, cp := range nk.chans {
str += "\t\t" + ch.Name + ": " + p.String() + "\n" str += "\t\t" + ch.Name + ": " + cp.String() + "\n"
} }
return str return str
} }

View File

@ -6,51 +6,63 @@ import (
// The state manager interface // The state manager interface
type StateTracker interface { type StateTracker interface {
// Nick methods
NewNick(nick string) *Nick NewNick(nick string) *Nick
GetNick(nick string) *Nick GetNick(nick string) *Nick
ReNick(old, neu string) ReNick(old, neu string)
DelNick(nick string) DelNick(nick string)
// Channel methods
NewChannel(channel string) *Channel NewChannel(channel string) *Channel
GetChannel(channel string) *Channel GetChannel(channel string) *Channel
DelChannel(channel string) DelChannel(channel string)
// Information about ME!
Me() *Nick
// And the tracking operations
IsOn(channel, nick string) bool IsOn(channel, nick string) bool
Associate(channel *Channel, nick *Nick)
Dissociate(channel *Channel, nick *Nick)
} }
// ... and a struct to implement it // ... and a struct to implement it ...
type stateTracker struct { type stateTracker struct {
// Map of channels we're on // Map of channels we're on
chans map[string]*Channel chans map[string]*Channel
// Map of nicks we know about // Map of nicks we know about
nicks map[string]*Nick nicks map[string]*Nick
// We need to keep state on who we are :-)
me *Nick
}
// ... and finally a constructor to make it.
func NewTracker(mynick string) *stateTracker {
st := &stateTracker{
chans: make(map[string]*Channel),
nicks: make(map[string]*Nick),
}
st.me = st.NewNick(mynick)
return st
} }
/******************************************************************************\ /******************************************************************************\
* tracker methods to create/look up nicks/channels * tracker methods to create/look up nicks/channels
\******************************************************************************/ \******************************************************************************/
func NewTracker() *stateTracker {
return &stateTracker{
chans: make(map[string]*Channel),
nicks: make(map[string]*Nick),
}
}
// Creates a new Nick, initialises it, and stores it so it // Creates a new Nick, initialises it, and stores it so it
// can be properly tracked for state management purposes. // can be properly tracked for state management purposes.
func (st *stateTracker) NewNick(nick string) *Nick { func (st *stateTracker) NewNick(n string) *Nick {
if _, ok := st.nicks[nick]; ok { if _, ok := st.nicks[n]; ok {
logging.Warn("StateTracker.NewNick(): %s already tracked.", nick) logging.Warn("StateTracker.NewNick(): %s already tracked.", n)
return nil return nil
} }
st.nicks[nick] = NewNick(nick) st.nicks[n] = NewNick(n)
st.nicks[nick].st = st return st.nicks[n]
return st.nicks[nick]
} }
// Returns a Nick for the nick n, if we're tracking it. // Returns a Nick for the nick n, if we're tracking it.
func (st *stateTracker) GetNick(n string) *Nick { func (st *stateTracker) GetNick(n string) *Nick {
if nick, ok := st.nicks[n]; ok { if nk, ok := st.nicks[n]; ok {
return nick return nk
} }
return nil return nil
} }
@ -58,11 +70,11 @@ func (st *stateTracker) GetNick(n string) *Nick {
// Signals to the tracker that a Nick should be tracked // Signals to the tracker that a Nick should be tracked
// under a "neu" nick rather than the old one. // under a "neu" nick rather than the old one.
func (st *stateTracker) ReNick(old, neu string) { func (st *stateTracker) ReNick(old, neu string) {
if n, ok := st.nicks[old]; ok { if nk, ok := st.nicks[old]; ok {
if _, ok := st.nicks[neu]; !ok { if _, ok := st.nicks[neu]; !ok {
st.nicks[old] = nil, false st.nicks[old] = nil, false
n.Nick = neu nk.Nick = neu
st.nicks[neu] = n st.nicks[neu] = nk
} else { } else {
logging.Warn("StateTracker.ReNick(): %s already exists.", neu) logging.Warn("StateTracker.ReNick(): %s already exists.", neu)
} }
@ -73,13 +85,36 @@ func (st *stateTracker) ReNick(old, neu string) {
// Removes a Nick from being tracked. // Removes a Nick from being tracked.
func (st *stateTracker) DelNick(n string) { func (st *stateTracker) DelNick(n string) {
if _, ok := st.nicks[n]; ok { if nk, ok := st.nicks[n]; ok {
st.nicks[n] = nil, false if nk != st.me {
st.delNick(nk)
} else {
logging.Warn("StateTracker.DelNick(): won't delete myself.")
}
} else { } else {
logging.Warn("StateTracker.DelNick(): %s not tracked.", n) logging.Warn("StateTracker.DelNick(): %s not tracked.", n)
} }
} }
func (st *stateTracker) delNick(nk *Nick) {
if nk == st.me {
// Shouldn't get here => internal state tracking code is fubar.
logging.Error("StateTracker.DelNick(): TRYING TO DELETE ME :-(")
return
}
st.nicks[nk.Nick] = nil, false
for ch, _ := range nk.chans {
nk.delChannel(ch)
ch.delNick(nk)
if len(ch.nicks) == 0 {
// Deleting a nick from tracking shouldn't empty any channels as
// *we* should be on the channel with them to be tracking them.
logging.Error("StateTracker.delNick(): deleting nick %s emptied "+
"channel %s, this shouldn't happen", nk.Nick, ch.Name)
}
}
}
// Creates a new Channel, initialises it, and stores it so it // Creates a new Channel, initialises it, and stores it so it
// can be properly tracked for state management purposes. // can be properly tracked for state management purposes.
func (st *stateTracker) NewChannel(c string) *Channel { func (st *stateTracker) NewChannel(c string) *Channel {
@ -88,7 +123,6 @@ func (st *stateTracker) NewChannel(c string) *Channel {
return nil return nil
} }
st.chans[c] = NewChannel(c) st.chans[c] = NewChannel(c)
st.chans[c].st = st
return st.chans[c] return st.chans[c]
} }
@ -102,11 +136,30 @@ func (st *stateTracker) GetChannel(c string) *Channel {
// Removes a Channel from being tracked. // Removes a Channel from being tracked.
func (st *stateTracker) DelChannel(c string) { func (st *stateTracker) DelChannel(c string) {
if _, ok := st.chans[c]; ok { if ch, ok := st.chans[c]; ok {
st.chans[c] = nil, false st.delChannel(ch)
} else {
logging.Warn("StateTracker.DelChannel(): %s not tracked.", c)
} }
} }
func (st *stateTracker) delChannel(ch *Channel) {
st.chans[ch.Name] = nil, false
for nk, _ := range ch.nicks {
ch.delNick(nk)
nk.delChannel(ch)
if len(nk.chans) == 0 && nk != st.me {
// We're no longer in any channels with this nick.
st.delNick(nk)
}
}
}
// Returns the Nick the state tracker thinks is Me.
func (st *stateTracker) Me() *Nick {
return st.me
}
// Returns true if both the channel c and the nick n are tracked // Returns true if both the channel c and the nick n are tracked
// and the nick is associated with the channel. // and the nick is associated with the channel.
func (st *stateTracker) IsOn(c, n string) bool { func (st *stateTracker) IsOn(c, n string) bool {
@ -117,3 +170,43 @@ func (st *stateTracker) IsOn(c, n string) bool {
} }
return false return false
} }
// Associates an already known nick with an already known channel.
func (st *stateTracker) Associate(ch *Channel, nk *Nick) {
if ch == nil || nk == nil {
logging.Error("StateTracker.Associate(): passed nil values :-(")
return
}
if nk.IsOn(ch) {
logging.Warn("StateTracker.Associate(): %s already on %s.",
nk.Nick, ch.Name)
return
}
cp := new(ChanPrivs)
ch.addNick(nk, cp)
nk.addChannel(ch, cp)
}
// Dissociates an already known nick from an already known channel.
// Does some tidying up to stop tracking nicks we're no longer on
// any common channels with, and channels we're no longer on.
func (st *stateTracker) Dissociate(ch *Channel, nk *Nick) {
switch {
case ch == nil || nk == nil:
logging.Error("StateTracker.Dissociate(): passed nil values :-(")
case !nk.IsOn(ch):
logging.Warn("StateTracker.Dissociate(): %s not on %s.",
nk.Nick, ch.Name)
case nk == st.me:
// I'm leaving the channel for some reason, so it won't be tracked.
st.delChannel(ch)
default:
// Remove the nick from the channel and the channel from the nick.
ch.delNick(nk)
nk.delChannel(ch)
if len(nk.chans) == 0 {
// We're no longer in any channels with this nick.
st.delNick(nk)
}
}
}

View File

@ -5,18 +5,18 @@ import (
) )
func TestNewNick(t *testing.T) { func TestNewNick(t *testing.T) {
st := NewTracker() st := NewTracker("mynick")
if len(st.nicks) != 0 { if len(st.nicks) != 1 {
t.Errorf("Nick list of new tracker is non-zero length.") t.Errorf("Nick list of new tracker is not 1 (me!).")
} }
nick := st.NewNick("test1") test1 := st.NewNick("test1")
if nick == nil || nick.Nick != "test1" || nick.st != st { if test1 == nil || test1.Nick != "test1" {
t.Errorf("Nick object created incorrectly by NewNick.") t.Errorf("Nick object created incorrectly by NewNick.")
} }
if n, ok := st.nicks["test1"]; !ok || n != nick || len(st.nicks) != 1 { if n, ok := st.nicks["test1"]; !ok || n != test1 || len(st.nicks) != 2 {
t.Errorf("Nick object stored incorrectly by NewNick.") t.Errorf("Nick object stored incorrectly by NewNick.")
} }
@ -26,7 +26,7 @@ func TestNewNick(t *testing.T) {
} }
func TestGetNick(t *testing.T) { func TestGetNick(t *testing.T) {
st := NewTracker() st := NewTracker("mynick")
test1 := NewNick("test1") test1 := NewNick("test1")
st.nicks["test1"] = test1 st.nicks["test1"] = test1
@ -37,13 +37,13 @@ func TestGetNick(t *testing.T) {
if n := st.GetNick("test2"); n != nil { if n := st.GetNick("test2"); n != nil {
t.Errorf("Nick unexpectedly returned by GetNick.") t.Errorf("Nick unexpectedly returned by GetNick.")
} }
if len(st.nicks) != 1 { if len(st.nicks) != 2 {
t.Errorf("Nick list changed size during GetNick.") t.Errorf("Nick list changed size during GetNick.")
} }
} }
func TestReNick(t *testing.T) { func TestReNick(t *testing.T) {
st := NewTracker() st := NewTracker("mynick")
test1 := NewNick("test1") test1 := NewNick("test1")
st.nicks["test1"] = test1 st.nicks["test1"] = test1
@ -59,7 +59,7 @@ func TestReNick(t *testing.T) {
if test1.Nick != "test2" { if test1.Nick != "test2" {
t.Errorf("Nick test1 not changed correctly.") t.Errorf("Nick test1 not changed correctly.")
} }
if len(st.nicks) != 1 { if len(st.nicks) != 2 {
t.Errorf("Nick list changed size during ReNick.") t.Errorf("Nick list changed size during ReNick.")
} }
@ -73,14 +73,14 @@ func TestReNick(t *testing.T) {
if n, ok := st.nicks["test1"]; !ok || n != test2 { if n, ok := st.nicks["test1"]; !ok || n != test2 {
t.Errorf("Nick test1 overwritten/deleted by ReNick.") t.Errorf("Nick test1 overwritten/deleted by ReNick.")
} }
if len(st.nicks) != 2 { if len(st.nicks) != 3 {
t.Errorf("Nick list changed size during ReNick.") t.Errorf("Nick list changed size during ReNick.")
} }
} }
func TestDelNick(t *testing.T) { func TestDelNick(t *testing.T) {
st := NewTracker() st := NewTracker("mynick")
test1 := NewNick("test1") test1 := NewNick("test1")
st.nicks["test1"] = test1 st.nicks["test1"] = test1
@ -90,7 +90,7 @@ func TestDelNick(t *testing.T) {
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.")
} }
if len(st.nicks) != 0 { if len(st.nicks) != 1 {
t.Errorf("Nick list still contains nicks after DelNick.") t.Errorf("Nick list still contains nicks after DelNick.")
} }
@ -98,13 +98,13 @@ func TestDelNick(t *testing.T) {
st.DelNick("test2") st.DelNick("test2")
if len(st.nicks) != 1 { if len(st.nicks) != 2 {
t.Errorf("DelNick had unexpected side-effects.") t.Errorf("DelNick had unexpected side-effects.")
} }
} }
func TestNewChannel(t *testing.T) { func TestNewChannel(t *testing.T) {
st := NewTracker() st := NewTracker("mynick")
if len(st.chans) != 0 { if len(st.chans) != 0 {
t.Errorf("Channel list of new tracker is non-zero length.") t.Errorf("Channel list of new tracker is non-zero length.")
@ -112,7 +112,7 @@ func TestNewChannel(t *testing.T) {
test1 := st.NewChannel("#test1") test1 := st.NewChannel("#test1")
if test1 == nil || test1.Name != "#test1" || test1.st != st { if test1 == nil || test1.Name != "#test1" {
t.Errorf("Channel object created incorrectly by NewChannel.") t.Errorf("Channel object created incorrectly by NewChannel.")
} }
if c, ok := st.chans["#test1"]; !ok || c != test1 || len(st.chans) != 1 { if c, ok := st.chans["#test1"]; !ok || c != test1 || len(st.chans) != 1 {
@ -125,7 +125,7 @@ func TestNewChannel(t *testing.T) {
} }
func TestGetChannel(t *testing.T) { func TestGetChannel(t *testing.T) {
st := NewTracker() st := NewTracker("mynick")
test1 := NewChannel("#test1") test1 := NewChannel("#test1")
st.chans["#test1"] = test1 st.chans["#test1"] = test1
@ -142,7 +142,7 @@ func TestGetChannel(t *testing.T) {
} }
func TestDelChannel(t *testing.T) { func TestDelChannel(t *testing.T) {
st := NewTracker() st := NewTracker("mynick")
test1 := NewChannel("#test1") test1 := NewChannel("#test1")
st.chans["#test1"] = test1 st.chans["#test1"] = test1
@ -166,7 +166,7 @@ func TestDelChannel(t *testing.T) {
} }
func TestIsOn(t *testing.T) { func TestIsOn(t *testing.T) {
st := NewTracker() st := NewTracker("mynick")
nick1 := NewNick("test1") nick1 := NewNick("test1")
st.nicks["test1"] = nick1 st.nicks["test1"] = nick1
@ -176,7 +176,9 @@ func TestIsOn(t *testing.T) {
if st.IsOn("#test1", "test1") { if st.IsOn("#test1", "test1") {
t.Errorf("test1 is not on #test1 (yet)") t.Errorf("test1 is not on #test1 (yet)")
} }
chan1.AddNick(nick1) cp := new(ChanPrivs)
chan1.addNick(nick1, cp)
nick1.addChannel(chan1, cp)
if !st.IsOn("#test1", "test1") { if !st.IsOn("#test1", "test1") {
t.Errorf("test1 is on #test1 (now)") t.Errorf("test1 is on #test1 (now)")
} }