2014-05-11 16:18:55 +00:00
|
|
|
/*
|
|
|
|
goircd -- minimalistic simple Internet Relay Chat (IRC) server
|
2020-01-07 15:27:02 +00:00
|
|
|
Copyright (C) 2014-2020 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"
|
|
|
|
)
|
|
|
|
|
|
|
|
// New client creation test. It must send an event about new client,
|
|
|
|
// two predefined messages from it and deletion one
|
|
|
|
func TestNewClient(t *testing.T) {
|
2014-05-14 12:29:54 +00:00
|
|
|
conn := NewTestingConn()
|
2014-05-11 16:18:55 +00:00
|
|
|
sink := make(chan ClientEvent)
|
2014-08-19 14:11:56 +00:00
|
|
|
host := "foohost"
|
2015-10-11 08:12:55 +00:00
|
|
|
hostname = &host
|
|
|
|
client := NewClient(conn)
|
2014-05-11 16:18:55 +00:00
|
|
|
go client.Processor(sink)
|
|
|
|
|
|
|
|
event := <-sink
|
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"
|
2014-05-11 16:18:55 +00:00
|
|
|
event = <-sink
|
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"
|
2014-05-11 16:18:55 +00:00
|
|
|
event = <-sink
|
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 <- ""
|
2014-05-11 16:18:55 +00:00
|
|
|
event = <-sink
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test replies formatting
|
|
|
|
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
|
|
|
|
client := NewClient(conn)
|
|
|
|
nickname := "мойник"
|
|
|
|
client.nickname = &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
|
|
|
}
|
|
|
|
}
|