func cmd(c *textproto.Conn, expectedCode int, format string, args ...interface{}) error { id, err := c.Cmd(format, args...) if err != nil { return err } c.StartResponse(id) _, _, err = c.ReadResponse(expectedCode) c.EndResponse(id) return err }
func CloseConn(conn *textproto.Conn) error { id, err := conn.Cmd("close") if err != nil { return err } conn.StartResponse(id) conn.EndResponse(id) err = conn.Close() if err != nil { return err } return nil }
// playScriptAgainst an existing connection, does not handle server greeting func playScriptAgainst(t *testing.T, c *textproto.Conn, script []scriptStep) error { for i, step := range script { id, err := c.Cmd(step.send) if err != nil { return fmt.Errorf("Step %d, failed to send %q: %v", i, step.send, err) } c.StartResponse(id) code, msg, err := c.ReadResponse(step.expect) if err != nil { err = fmt.Errorf("Step %d, sent %q, expected %v, got %v: %q", i, step.send, step.expect, code, msg) } c.EndResponse(id) if err != nil { // Return after c.EndResponse so we don't hang the connection return err } } return nil }
cryptoConfig: &CryptoConfig{ Implicit: true, Force: false, TlsConfig: tlsConfig, }, clientExplicitTls: false, clientImplicitTls: true, }, } for _, tv := range variants { variant := tv Describe(variant.name, func() { cmd := func(format string, args ...interface{}) { _, err := c.Cmd(format, args...) Expect(err).NotTo(HaveOccurred()) } getres := func(format string, args ...interface{}) func(int) (string, error) { return func(code int) (string, error) { cmd(format, args...) _, lineRes, err := c.ReadResponse(code) Expect(err).NotTo(HaveOccurred()) return lineRes, err } } res := func(format string, args ...interface{}) func(int, string) {