Exemplo n.º 1
0
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
}
Exemplo n.º 2
0
// 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
}
Exemplo n.º 3
0
	}

	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) {
				return func(code int, line string) {
					lineRes, err := getres(format, args...)(code)

					if err != nil {
						return
					}

					Expect(lineRes).To(Equal(line))