Пример #1
0
func TestWrite(t *testing.T) {
	for _, tt := range writeTests {
		var buf bytes.Buffer
		rw := bufio.ReadWriter{Writer: bufio.NewWriter(&buf)}
		c := redis.NewConnBufio(rw)
		err := c.Send(tt.args[0].(string), tt.args[1:]...)
		if err != nil {
			t.Errorf("Send(%v) returned error %v", tt.args, err)
			continue
		}
		rw.Flush()
		actual := buf.String()
		if actual != tt.expected {
			t.Errorf("Send(%v) = %q, want %q", tt.args, actual, tt.expected)
		}
	}
}
Пример #2
0
func TestRead(t *testing.T) {
	for _, tt := range readTests {
		rw := bufio.ReadWriter{
			Reader: bufio.NewReader(strings.NewReader(tt.reply)),
			Writer: bufio.NewWriter(nil), // writer need to support Flush
		}
		c := redis.NewConnBufio(rw)
		actual, err := c.Receive()
		if tt.expected == errorSentinel {
			if err == nil {
				t.Errorf("Receive(%q) did not return expected error", tt.reply)
			}
		} else {
			if err != nil {
				t.Errorf("Receive(%q) returned error %v", tt.reply, err)
				continue
			}
			if !reflect.DeepEqual(actual, tt.expected) {
				t.Errorf("Receive(%q) = %v, want %v", tt.reply, actual, tt.expected)
			}
		}
	}
}