Added Client.Query, added tests for query target

This commit is contained in:
2018-06-26 13:02:36 +02:00
parent 0fbebfc3f5
commit 6377349c28
2 changed files with 37 additions and 0 deletions
+10
View File
@@ -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()
+27
View File
@@ -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
}},
},