Exemplo n.º 1
0
func (tc *testConnection) Setup(t *testing.T) {
	tc.nc, tc.ns = net.Pipe()
	tc.s = test.NewTestServer(t, tc.ns)
	tc.c = NewConnection(tc.nc)
	tc.ec = make(chan error, 1)

	tc.Add(1)
	go func() {
		tc.ec <- tc.c.Run()
		tc.Done()
	}()
}
Exemplo n.º 2
0
func (tc *testClient) ResetConnection() {
	// Close current test server, if any
	if tc.s != nil {
		tc.s.Close()
	}

	nc, ns := net.Pipe()

	// Pass new client side of the connection to Dialer
	tc.ncc <- nc

	// New server
	tc.s = test.NewTestServer(tc.T, ns)
}
Exemplo n.º 3
0
func testHandshake(t *testing.T, user, pass string, ssl bool) {
	c, s := net.Pipe()
	srv := test.NewTestServer(t, s)
	wg := sync.WaitGroup{}

	wg.Add(1)

	go func() {
		h := Handshake{
			Username: user,
			Password: pass,
		}

		_, e := h.Handshake(c)
		if e != nil {
			t.Error(e)
		}

		wg.Done()
	}()

	var p string

	if ssl {
		p = "true"
	} else {
		p = "false"
	}

	p = fmt.Sprintf("INFO {\"ssl_required\":%s}\r\n", p)
	srv.AssertWrite(p)

	if ssl {
		srv.StartTLS()
	}

	p = fmt.Sprintf("CONNECT {\"verbose\":true,\"pedantic\":true,\"user\":\"%s\",\"pass\":\"%s\"}\r\n", user, pass)
	srv.AssertRead(p)

	p = fmt.Sprintf("+OK\r\n")
	srv.AssertWrite(p)

	wg.Wait()
}