-
Notifications
You must be signed in to change notification settings - Fork 5
/
fake_client.go
46 lines (39 loc) · 1.13 KB
/
fake_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package clients
import (
"bytes"
"crypto/rand"
"encoding/hex"
"net"
)
// FakeClientConn implements ClientConn, but isn't an actual network connection.
// Can still be passed into resp.ReadMessage and other things that take in
// io.Readers and io.Writers. Used for testing here and other places
type FakeClientConn struct {
*bytes.Buffer
}
// NewFakeClientConn initializes a FakeClientConn and returns it
func NewFakeClientConn() *FakeClientConn {
return &FakeClientConn{
bytes.NewBuffer(make([]byte, 0, 1024)),
}
}
// Close does nothing and always returns nil. It is only here to implement the
// ClientConn interface
func (fconn *FakeClientConn) Close() error {
return nil
}
// RemoteAddr always returns nil. It is only here to implement the ClientConn
// interface
func (fconn *FakeClientConn) RemoteAddr() net.Addr {
return nil
}
// Kind of an odd place for this, but it has to go somewhere.
// RandQueueName returns a random string to use as a queue name. Used for
// testing in a few places
func RandQueueName() string {
b := make([]byte, 10)
if _, err := rand.Read(b); err != nil {
panic(err)
}
return hex.EncodeToString(b)
}