2014-05-11 16:18:55 +00:00
|
|
|
/*
|
|
|
|
goircd -- minimalistic simple Internet Relay Chat (IRC) server
|
2021-01-05 17:48:29 +00:00
|
|
|
Copyright (C) 2014-2021 Sergey Matveev <stargrave@stargrave.org>
|
2014-05-11 16:18:55 +00:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2019-09-27 08:32:53 +00:00
|
|
|
the Free Software Foundation, version 3 of the License.
|
2014-05-11 16:18:55 +00:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2015-05-09 15:27:06 +00:00
|
|
|
|
2014-05-11 16:18:55 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewClient(t *testing.T) {
|
2014-05-14 12:29:54 +00:00
|
|
|
conn := NewTestingConn()
|
2020-11-06 17:10:06 +00:00
|
|
|
events := make(chan ClientEvent)
|
2014-08-19 14:11:56 +00:00
|
|
|
host := "foohost"
|
2015-10-11 08:12:55 +00:00
|
|
|
hostname = &host
|
2020-11-06 17:10:06 +00:00
|
|
|
client := NewClient(conn, events)
|
|
|
|
defer func() {
|
|
|
|
client.Close()
|
|
|
|
}()
|
2014-05-11 16:18:55 +00:00
|
|
|
|
2020-11-06 17:10:06 +00:00
|
|
|
event := <-events
|
2014-08-09 12:42:19 +00:00
|
|
|
if event.eventType != EventNew {
|
2014-05-18 11:27:17 +00:00
|
|
|
t.Fatal("no NEW event", event)
|
2014-05-11 16:18:55 +00:00
|
|
|
}
|
2014-05-14 12:29:54 +00:00
|
|
|
conn.inbound <- "foo"
|
2020-11-06 17:10:06 +00:00
|
|
|
event = <-events
|
2014-08-09 12:42:19 +00:00
|
|
|
if (event.eventType != EventMsg) || (event.text != "foo") {
|
2014-05-18 11:27:17 +00:00
|
|
|
t.Fatal("no first MSG", event)
|
2014-05-11 16:18:55 +00:00
|
|
|
}
|
2014-05-14 12:29:54 +00:00
|
|
|
conn.inbound <- "bar"
|
2020-11-06 17:10:06 +00:00
|
|
|
event = <-events
|
2014-08-09 12:42:19 +00:00
|
|
|
if (event.eventType != EventMsg) || (event.text != "bar") {
|
2014-05-18 11:27:17 +00:00
|
|
|
t.Fatal("no second MSG", event)
|
2014-05-11 16:18:55 +00:00
|
|
|
}
|
2014-05-14 12:29:54 +00:00
|
|
|
conn.inbound <- ""
|
2020-11-06 17:10:06 +00:00
|
|
|
event = <-events
|
2014-08-09 12:42:19 +00:00
|
|
|
if event.eventType != EventDel {
|
2014-05-18 11:27:17 +00:00
|
|
|
t.Fatal("no client termination", event)
|
2014-05-11 16:18:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientReplies(t *testing.T) {
|
2014-05-14 12:29:54 +00:00
|
|
|
conn := NewTestingConn()
|
2014-08-19 14:11:56 +00:00
|
|
|
host := "foohost"
|
2015-10-11 08:12:55 +00:00
|
|
|
hostname = &host
|
2020-11-06 17:10:06 +00:00
|
|
|
client := NewClient(conn, make(chan ClientEvent, 2))
|
|
|
|
defer func() {
|
|
|
|
client.Close()
|
|
|
|
}()
|
|
|
|
client.nickname = "мойник"
|
2014-05-11 16:18:55 +00:00
|
|
|
|
|
|
|
client.Reply("hello")
|
2014-05-14 12:29:54 +00:00
|
|
|
if r := <-conn.outbound; r != ":foohost hello\r\n" {
|
2014-05-18 11:27:17 +00:00
|
|
|
t.Fatal("did not recieve hello message", r)
|
2014-05-11 16:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
client.ReplyParts("200", "foo", "bar")
|
2014-05-14 12:29:54 +00:00
|
|
|
if r := <-conn.outbound; r != ":foohost 200 foo :bar\r\n" {
|
2014-05-18 11:27:17 +00:00
|
|
|
t.Fatal("did not recieve 200 message", r)
|
2014-05-11 16:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
client.ReplyNicknamed("200", "foo", "bar")
|
2014-05-14 12:29:54 +00:00
|
|
|
if r := <-conn.outbound; r != ":foohost 200 мойник foo :bar\r\n" {
|
2014-05-18 11:27:17 +00:00
|
|
|
t.Fatal("did not recieve nicknamed message", r)
|
2014-05-11 16:18:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
client.ReplyNotEnoughParameters("CMD")
|
2014-05-14 12:29:54 +00:00
|
|
|
if r := <-conn.outbound; r != ":foohost 461 мойник CMD :Not enough parameters\r\n" {
|
2014-05-18 11:27:17 +00:00
|
|
|
t.Fatal("did not recieve 461 message", r)
|
2014-05-11 16:18:55 +00:00
|
|
|
}
|
|
|
|
}
|