Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. package busybus
  2.  
  3. import (
  4. "bufio"
  5. "net"
  6. )
  7.  
  8. type Client struct {
  9. counter integer
  10. conn net.Conn
  11. bufin *bufio.Reader
  12. bufout *bufio.Writer
  13. messages chan string
  14. state string
  15. }
  16.  
  17. func NewClient(conn net.Conn, messages chan string) *Client {
  18. return &Client{
  19. counter: 0,
  20. conn: conn,
  21. bufin: bufio.NewReader(conn),
  22. bufout: bufio.NewWriter(conn),
  23. messages: messages,
  24. state: "waiting",
  25.  
  26. }
  27. }
  28.  
  29. package busybus
  30.  
  31. import (
  32. "net"
  33. "testing"
  34. )
  35.  
  36. func TestNewClient(t *testing.T) {
  37. ln, _ := net.Listen("tcp", ":65535")
  38. conn, _ := ln.Accept()
  39. messages := make(chan string)
  40.  
  41. client := NewClient(conn, messages)
  42. if client.conn != conn {
  43. t.Errorf("NewClient(%q, %q).conn == %q, want %q", conn, messages, client.conn, conn)
  44. }
  45. }
  46.  
  47. client.buf = bufio.NewReadWriter(...)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement