Browse Source

Added Client.Query, added tests for query target

master
Gisle Aune 7 years ago
parent
commit
6377349c28
  1. 10
      client.go
  2. 27
      client_test.go

10
client.go

@ -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
client_test.go

@ -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
}},
},

Loading…
Cancel
Save