@@ -33,7 +33,7 @@ func (t *testReadWriteCloser) Close() error {
33
33
return nil
34
34
}
35
35
36
- func testReadMessage (t * testing.T , c * Client ) * Message {
36
+ func testReadMessage (t * testing.T , c * Conn ) * Message {
37
37
m , err := c .ReadMessage ()
38
38
if err != nil {
39
39
t .Error (err )
@@ -66,22 +66,17 @@ func testLines(t *testing.T, rwc *testReadWriteCloser, expected []string) {
66
66
67
67
func TestClient (t * testing.T ) {
68
68
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 )
80
70
81
71
// Test writing a message
82
72
m := & Message {Prefix : & Prefix {}, Command : "PING" , Params : []string {"Hello World" }}
83
73
c .WriteMessage (m )
74
+ testLines (t , rwc , []string {
75
+ "PING :Hello World" ,
76
+ })
84
77
78
+ // Test with Writef
79
+ c .Writef ("PING :%s" , "Hello World" )
85
80
testLines (t , rwc , []string {
86
81
"PING :Hello World" ,
87
82
})
@@ -94,37 +89,10 @@ func TestClient(t *testing.T) {
94
89
t .Errorf ("Message returned by client did not match input" )
95
90
}
96
91
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
-
113
92
// Test welcome message
114
93
rwc .server .WriteString ("001 test_nick\r \n " )
115
94
m = testReadMessage (t , c )
116
95
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
-
128
96
// Ensure CTCP messages are parsed
129
97
rwc .server .WriteString (":world PRIVMSG :\x01 VERSION\x01 \r \n " )
130
98
m = testReadMessage (t , c )
@@ -135,46 +103,11 @@ func TestClient(t *testing.T) {
135
103
t .Error ("Wrong CTCP command" )
136
104
}
137
105
138
- // Test CTCPReply
139
- c .CTCPReply (m , "VERSION 42" )
140
- testLines (t , rwc , []string {
141
- "NOTICE world :\x01 VERSION 42\x01 " ,
142
- })
143
-
144
106
// This is an odd one... if there wasn't any output, it'll hit
145
107
// EOF, so we expect an error here so we can test an error
146
108
// condition.
147
109
_ , err := c .ReadMessage ()
148
110
if err != io .EOF {
149
111
t .Error ("Didn't get expected EOF error" )
150
112
}
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
- }
180
113
}
0 commit comments