Explorar el Código

More working tests.

We verify responses from "echo" user.
Echo returns the PRIVMSG NOTICE commands back to us.
We can verify the CTCP PING, VERSION, TIME.
Steve Thielemann hace 3 años
padre
commit
5fd4d41fd6
Se han modificado 1 ficheros con 47 adiciones y 4 borrados
  1. 47 4
      client_test.go

+ 47 - 4
client_test.go

@@ -100,6 +100,8 @@ func ircWrite(server net.Conn, output string, t *testing.T) {
 	server.Write([]byte(output + "\r\n"))
 }
 
+var abortAfter int = 150 // Milliseconds to abort part 3
+
 // mock up an irc server
 func ircServer(listener net.Listener, t *testing.T, config *IRCConfig) {
 	var server net.Conn
@@ -291,7 +293,7 @@ func ircServer(listener net.Listener, t *testing.T, config *IRCConfig) {
 		t.Error("Expected to pass part2 (ns identify/+r)")
 	}
 
-	time.AfterFunc(time.Millisecond*time.Duration(100), func() { server.Close() })
+	time.AfterFunc(time.Millisecond*time.Duration(abortAfter), func() { server.Close() })
 
 	t.Log("Ok, Identified...")
 
@@ -461,11 +463,23 @@ func TestConnectAutojoin(t *testing.T) {
 	var Msg IRCMsg
 	var motd, identify bool
 	var joins int
+	var expect string
+	var ctcpExpect []string = []string{"VERSION",
+		"TIME",
+		"PING 12345",
+	}
+	var noticeExpect []string = []string{"Testing",
+		"VERSION red-green.com/irc-client",
+		"TIME ",
+		"PING 12345",
+	}
 
 	for Msg = range FromIRC {
-		if (Msg.Cmd == "ACTION") || (Msg.Cmd == "NOTICE") {
-			t.Log(Msg)
-		}
+		/*
+			if (Msg.Cmd == "ACTION") || (Msg.Cmd == "NOTICE") {
+				t.Log(Msg)
+			}
+		*/
 		if Msg.Cmd == "EndMOTD" {
 			t.Log("Got EndMOTD")
 			motd = true
@@ -487,6 +501,29 @@ func TestConnectAutojoin(t *testing.T) {
 				config.Msg("#test", "Message 2")
 			}
 		}
+		if Msg.Cmd == "CTCP" {
+			expect = ctcpExpect[0]
+			ctcpExpect = ctcpExpect[1:]
+			if Msg.Msg != expect {
+				t.Errorf("CTCP Got %s, Expected %s", Msg.Msg, expect)
+			}
+		}
+		if Msg.Cmd == "NOTICE" {
+			expect = noticeExpect[0]
+			if expect != "Testing" {
+				expect += "\x01" + expect
+			}
+			noticeExpect = noticeExpect[1:]
+			if !strings.HasPrefix(Msg.Msg, expect) {
+				t.Errorf("NOTICE Got [%s], Expected [%s]", Msg.Msg, expect)
+			}
+		}
+		if Msg.Cmd == "ACTION" {
+			expect = "dances."
+			if Msg.Msg != expect {
+				t.Errorf("ACTION Got %s, Expected %s", Msg.Msg, expect)
+			}
+		}
 	}
 
 	if joins != 2 {
@@ -498,6 +535,12 @@ func TestConnectAutojoin(t *testing.T) {
 	if !identify {
 		t.Error("Missing Identified")
 	}
+	if len(noticeExpect) != 0 {
+		t.Errorf("Expected more NOTICEs (%d)", len(noticeExpect))
+	}
+	if len(ctcpExpect) != 0 {
+		t.Errorf("Expected more CTCPs (%d)", len(ctcpExpect))
+	}
 
 	if config.MyNick != config.Nick {
 		t.Errorf("Got %s, Expected %s", config.MyNick, config.Nick)