mirror of https://github.com/gissleh/irc.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.1 KiB
56 lines
1.1 KiB
package irctest_test
|
|
|
|
import (
|
|
"net"
|
|
"testing"
|
|
|
|
"github.com/gissleh/irc/internal/irctest"
|
|
)
|
|
|
|
func TestInteraction(t *testing.T) {
|
|
interaction := irctest.Interaction{
|
|
Lines: []irctest.InteractionLine{
|
|
{Client: "FIRST MESSAGE"},
|
|
{Server: "SERVER MESSAGE"},
|
|
{Client: "SECOND MESSAGE"},
|
|
},
|
|
}
|
|
|
|
addr, err := interaction.Listen()
|
|
if err != nil {
|
|
t.Fatal("Listen:", err)
|
|
}
|
|
|
|
conn, err := net.Dial("tcp", addr)
|
|
if err != nil {
|
|
t.Fatal("Dial:", err)
|
|
}
|
|
|
|
_, err = conn.Write([]byte("FIRST MESSAGE\r\n"))
|
|
if err != nil {
|
|
t.Fatal("Write:", err)
|
|
}
|
|
|
|
buffer := make([]byte, 64)
|
|
n, err := conn.Read(buffer)
|
|
if err != nil {
|
|
t.Fatal("Read:", err)
|
|
}
|
|
if string(buffer[:n]) != "SERVER MESSAGE\r\n" {
|
|
t.Fatal("Read not correct:", string(buffer[:n]))
|
|
}
|
|
|
|
_, err = conn.Write([]byte("SECOND MESSAGE\r\n"))
|
|
if err != nil {
|
|
t.Fatal("Write 2:", err)
|
|
}
|
|
|
|
interaction.Wait()
|
|
|
|
if interaction.Failure != nil {
|
|
t.Error("Index:", interaction.Failure.Index)
|
|
t.Error("Result:", interaction.Failure.Result)
|
|
t.Error("NetErr:", interaction.Failure.NetErr)
|
|
t.FailNow()
|
|
}
|
|
}
|