Documentation ¶
Overview ¶
Package nettest provides a set of network helpers for when unit testing networks
Uses a channel log the messages recieved by the server ¶
Usage:
done := make(chan string) addr, sock, srvWg := CreateServer(t, tc.net, tc.la, done) defer srvWg.Wait() defer os.Remove(addr.String()) defer sock.Close() s, err := net.Dial(tc.net, addr.String()) defer s.Close() fmt.Fprintf(s, "test message\n") if "test message\n" != <-done { t.Error("message not recieved") }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateServer ¶
func CreateServer(t *testing.T, n, la string, done chan<- string) (addr net.Addr, sock io.Closer, wg *sync.WaitGroup)
CreateServer creates a network server that will output all messages to the done channel for use with testing
It can create `udp`, `unixgram`, and `tcp` networks ¶
Example:
done := make(chan string) addr, sock, srvWg := CreateServer(t, tc.net, tc.la, done) defer srvWg.Wait() defer os.Remove(addr.String()) defer sock.Close() s, err := net.Dial(tc.net, addr.String()) defer s.Close() fmt.Fprintf(s, "test message\n") if "test message\n" != <-done { t.Error("message not recieved") }
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.