Skip to content

Commit d9c465e

Browse files
committed
Remove *irc.Client
1 parent e0547ed commit d9c465e

File tree

3 files changed

+7
-192
lines changed

3 files changed

+7
-192
lines changed

client.go

-108
This file was deleted.

client_test.go renamed to conn_test.go

+7-74
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (t *testReadWriteCloser) Close() error {
3333
return nil
3434
}
3535

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

6767
func TestClient(t *testing.T) {
6868
rwc := newTestReadWriteCloser()
69-
c := NewClient(rwc, "test_nick", "test_user", "test_name", "test_pass")
70-
71-
testLines(t, rwc, []string{
72-
"PASS test_pass",
73-
"NICK test_nick",
74-
"USER test_user 0.0.0.0 0.0.0.0 :test_name",
75-
})
76-
77-
if c.CurrentNick() != "test_nick" {
78-
t.Errorf("c.CurrentNick was %s, not test_nick", c.CurrentNick())
79-
}
69+
c := NewConn(rwc)
8070

8171
// Test writing a message
8272
m := &Message{Prefix: &Prefix{}, Command: "PING", Params: []string{"Hello World"}}
8373
c.WriteMessage(m)
74+
testLines(t, rwc, []string{
75+
"PING :Hello World",
76+
})
8477

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

97-
// Test specific messages
98-
rwc.server.WriteString("PING :42\r\n")
99-
m = testReadMessage(t, c)
100-
101-
testLines(t, rwc, []string{
102-
"PONG :42",
103-
})
104-
105-
// Test nick change
106-
rwc.server.WriteString(":test_nick NICK new_test_nick\r\n")
107-
m = testReadMessage(t, c)
108-
109-
if c.CurrentNick() != "new_test_nick" {
110-
t.Errorf("c.CurrentNick was %s, not new_test_nick", c.CurrentNick())
111-
}
112-
11392
// Test welcome message
11493
rwc.server.WriteString("001 test_nick\r\n")
11594
m = testReadMessage(t, c)
11695

117-
if c.CurrentNick() != "test_nick" {
118-
t.Errorf("c.CurrentNick was %s, not test_nick", c.CurrentNick())
119-
}
120-
121-
// Test nick collisions
122-
rwc.server.WriteString("437\r\n")
123-
m = testReadMessage(t, c)
124-
testLines(t, rwc, []string{
125-
"NICK test_nick_",
126-
})
127-
12896
// Ensure CTCP messages are parsed
12997
rwc.server.WriteString(":world PRIVMSG :\x01VERSION\x01\r\n")
13098
m = testReadMessage(t, c)
@@ -135,46 +103,11 @@ func TestClient(t *testing.T) {
135103
t.Error("Wrong CTCP command")
136104
}
137105

138-
// Test CTCPReply
139-
c.CTCPReply(m, "VERSION 42")
140-
testLines(t, rwc, []string{
141-
"NOTICE world :\x01VERSION 42\x01",
142-
})
143-
144106
// This is an odd one... if there wasn't any output, it'll hit
145107
// EOF, so we expect an error here so we can test an error
146108
// condition.
147109
_, err := c.ReadMessage()
148110
if err != io.EOF {
149111
t.Error("Didn't get expected EOF error")
150112
}
151-
152-
mInvalid := &Message{}
153-
mFromUser := &Message{
154-
Prefix: &Prefix{Name: "seabot"},
155-
Command: "PRIVMSG",
156-
Params: []string{"seabot", "Hello"},
157-
}
158-
mFromChannel := &Message{
159-
Prefix: &Prefix{Name: "seabot"},
160-
Command: "PRIVMSG",
161-
Params: []string{"#seabot", "Hello"},
162-
}
163-
164-
c.MentionReply(mFromUser, "hi")
165-
c.MentionReply(mFromChannel, "hi")
166-
testLines(t, rwc, []string{
167-
"PRIVMSG seabot :hi",
168-
"PRIVMSG #seabot :seabot: hi",
169-
})
170-
171-
if c.Reply(mInvalid, "TEST") == nil {
172-
t.Error("Expected error, didn't get one")
173-
}
174-
if c.MentionReply(mInvalid, "TEST") == nil {
175-
t.Error("Expected error, didn't get one")
176-
}
177-
if c.CTCPReply(mInvalid, "TEST") == nil {
178-
t.Errorf("Expected error, didn't get one")
179-
}
180113
}

utils.go

-10
This file was deleted.

0 commit comments

Comments
 (0)