]> Cypherpunks.ru repositories - goircd.git/blobdiff - daemon_test.go
HasPrefix is not necessary before TrimPrefix
[goircd.git] / daemon_test.go
index 1c86f351d819816682b095d063d5f98116471d35..3db72cb6b73fee9d3636d6a9a30133ee8e8d5ac9 100644 (file)
@@ -1,6 +1,6 @@
 /*
 goircd -- minimalistic simple Internet Relay Chat (IRC) server
-Copyright (C) 2014 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2014-2015 Sergey Matveev <stargrave@stargrave.org>
 
 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
@@ -15,6 +15,7 @@ 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/>.
 */
+
 package main
 
 import (
@@ -25,11 +26,12 @@ import (
 )
 
 func TestRegistrationWorkflow(t *testing.T) {
-       daemon := NewDaemon("foohost", "", nil, nil)
+       host := "foohost"
+       daemon := NewDaemon("ver1", &host, nil, nil, nil, nil)
        events := make(chan ClientEvent)
        go daemon.Processor(events)
        conn := NewTestingConn()
-       client := NewClient("foohost", conn)
+       client := NewClient(&host, conn)
        go client.Processor(events)
 
        conn.inbound <- "UNEXISTENT CMD" // should recieve nothing on this
@@ -113,14 +115,16 @@ func TestRegistrationWorkflow(t *testing.T) {
 func TestMotd(t *testing.T) {
        fd, err := ioutil.TempFile("", "motd")
        if err != nil {
-               t.Fatal("can not create temporary file")
+               t.Fatalf("can not create temporary file: %v", err)
        }
        defer os.Remove(fd.Name())
-       fd.Write([]byte("catched\n"))
+       fd.WriteString("catched\n")
 
        conn := NewTestingConn()
-       client := NewClient("foohost", conn)
-       daemon := NewDaemon("foohost", fd.Name(), nil, nil)
+       host := "foohost"
+       client := NewClient(&host, conn)
+       motdName := fd.Name()
+       daemon := NewDaemon("ver1", &host, &motdName, nil, nil, nil)
 
        daemon.SendMotd(client)
        if r := <-conn.outbound; !strings.HasPrefix(r, ":foohost 375") {
@@ -129,7 +133,7 @@ func TestMotd(t *testing.T) {
        if r := <-conn.outbound; !strings.Contains(r, "372 * :- catched\r\n") {
                t.Fatal("MOTD contents", r)
        }
-       if r := <-conn.outbound; !strings.HasPrefix(r, ":foohost 376") {
-               t.Fatal("MOTD end", r)
+       if got, want := <-conn.outbound, ":foohost 376"; !strings.HasPrefix(got, want) {
+               t.Fatalf("MOTD end: got %q, want prefix %q", got, want)
        }
 }