mirror of
https://github.com/gissleh/irc.git
synced 2026-09-29 00:05:34 +00:00
Added Client.Query, added tests for query target
This commit is contained in:
@@ -419,6 +419,16 @@ func (client *Client) Channel(name string) *Channel {
|
||||
return target.(*Channel)
|
||||
}
|
||||
|
||||
// Query is a shorthand for getting a query target and type asserting it.
|
||||
func (client *Client) Query(name string) *Query {
|
||||
target := client.Target("query", name)
|
||||
if target == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return target.(*Query)
|
||||
}
|
||||
|
||||
// AddTarget adds a target to the client, generating a unique ID for it.
|
||||
func (client *Client) AddTarget(target Target) (id string, err error) {
|
||||
client.mutex.Lock()
|
||||
|
||||
@@ -130,6 +130,33 @@ func TestClient(t *testing.T) {
|
||||
return errors.New("Hunter2 has the wrong away message: " + userHunter2.Away)
|
||||
}
|
||||
|
||||
return nil
|
||||
}},
|
||||
{Kind: 'S', Data: ":Hunter2!~test2@172.17.37.1 PRIVMSG Test768 :Hello, World"},
|
||||
{Kind: 'S', Data: "PING :archgisle.lan"}, // Ping/Pong to sync.
|
||||
{Kind: 'C', Data: "PONG :archgisle.lan"},
|
||||
{Callback: func() error {
|
||||
query := client.Query("Hunter2")
|
||||
if query == nil {
|
||||
return errors.New("Did not find query")
|
||||
}
|
||||
|
||||
return nil
|
||||
}},
|
||||
{Kind: 'S', Data: ":Hunter2!~test2@172.17.37.1 NICK SevenAsterisks"},
|
||||
{Kind: 'S', Data: "PING :archgisle.lan"}, // Ping/Pong to sync.
|
||||
{Kind: 'C', Data: "PONG :archgisle.lan"},
|
||||
{Callback: func() error {
|
||||
oldQuerry := client.Query("Hunter2")
|
||||
if oldQuerry != nil {
|
||||
return errors.New("Did find query by old name")
|
||||
}
|
||||
|
||||
query := client.Query("SevenAsterisks")
|
||||
if query == nil {
|
||||
return errors.New("Did not find query by new name")
|
||||
}
|
||||
|
||||
return nil
|
||||
}},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user