Skip to content

Commit

Permalink
Merge pull request #26 from belak/remove-client
Browse files Browse the repository at this point in the history
Remove *irc.Client
  • Loading branch information
belak committed Sep 23, 2015
2 parents e0547ed + d9c465e commit 4c5b611
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 192 deletions.
108 changes: 0 additions & 108 deletions client.go

This file was deleted.

81 changes: 7 additions & 74 deletions client_test.go → conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (t *testReadWriteCloser) Close() error {
return nil
}

func testReadMessage(t *testing.T, c *Client) *Message {
func testReadMessage(t *testing.T, c *Conn) *Message {
m, err := c.ReadMessage()
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -66,22 +66,17 @@ func testLines(t *testing.T, rwc *testReadWriteCloser, expected []string) {

func TestClient(t *testing.T) {
rwc := newTestReadWriteCloser()
c := NewClient(rwc, "test_nick", "test_user", "test_name", "test_pass")

testLines(t, rwc, []string{
"PASS test_pass",
"NICK test_nick",
"USER test_user 0.0.0.0 0.0.0.0 :test_name",
})

if c.CurrentNick() != "test_nick" {
t.Errorf("c.CurrentNick was %s, not test_nick", c.CurrentNick())
}
c := NewConn(rwc)

// Test writing a message
m := &Message{Prefix: &Prefix{}, Command: "PING", Params: []string{"Hello World"}}
c.WriteMessage(m)
testLines(t, rwc, []string{
"PING :Hello World",
})

// Test with Writef
c.Writef("PING :%s", "Hello World")
testLines(t, rwc, []string{
"PING :Hello World",
})
Expand All @@ -94,37 +89,10 @@ func TestClient(t *testing.T) {
t.Errorf("Message returned by client did not match input")
}

// Test specific messages
rwc.server.WriteString("PING :42\r\n")
m = testReadMessage(t, c)

testLines(t, rwc, []string{
"PONG :42",
})

// Test nick change
rwc.server.WriteString(":test_nick NICK new_test_nick\r\n")
m = testReadMessage(t, c)

if c.CurrentNick() != "new_test_nick" {
t.Errorf("c.CurrentNick was %s, not new_test_nick", c.CurrentNick())
}

// Test welcome message
rwc.server.WriteString("001 test_nick\r\n")
m = testReadMessage(t, c)

if c.CurrentNick() != "test_nick" {
t.Errorf("c.CurrentNick was %s, not test_nick", c.CurrentNick())
}

// Test nick collisions
rwc.server.WriteString("437\r\n")
m = testReadMessage(t, c)
testLines(t, rwc, []string{
"NICK test_nick_",
})

// Ensure CTCP messages are parsed
rwc.server.WriteString(":world PRIVMSG :\x01VERSION\x01\r\n")
m = testReadMessage(t, c)
Expand All @@ -135,46 +103,11 @@ func TestClient(t *testing.T) {
t.Error("Wrong CTCP command")
}

// Test CTCPReply
c.CTCPReply(m, "VERSION 42")
testLines(t, rwc, []string{
"NOTICE world :\x01VERSION 42\x01",
})

// This is an odd one... if there wasn't any output, it'll hit
// EOF, so we expect an error here so we can test an error
// condition.
_, err := c.ReadMessage()
if err != io.EOF {
t.Error("Didn't get expected EOF error")
}

mInvalid := &Message{}
mFromUser := &Message{
Prefix: &Prefix{Name: "seabot"},
Command: "PRIVMSG",
Params: []string{"seabot", "Hello"},
}
mFromChannel := &Message{
Prefix: &Prefix{Name: "seabot"},
Command: "PRIVMSG",
Params: []string{"#seabot", "Hello"},
}

c.MentionReply(mFromUser, "hi")
c.MentionReply(mFromChannel, "hi")
testLines(t, rwc, []string{
"PRIVMSG seabot :hi",
"PRIVMSG #seabot :seabot: hi",
})

if c.Reply(mInvalid, "TEST") == nil {
t.Error("Expected error, didn't get one")
}
if c.MentionReply(mInvalid, "TEST") == nil {
t.Error("Expected error, didn't get one")
}
if c.CTCPReply(mInvalid, "TEST") == nil {
t.Errorf("Expected error, didn't get one")
}
}
10 changes: 0 additions & 10 deletions utils.go

This file was deleted.

0 comments on commit 4c5b611

Please sign in to comment.