fix unit tests

master
Jordan Orelli 11 years ago
parent 61947ead11
commit 1740f13db8

@ -47,7 +47,8 @@ func main() {
defer conn.Close() defer conn.Close()
if options.password != "" { if options.password != "" {
fmt.Fprintf(conn, "*2\r\n$4\r\nauth\r\n$%d\r\n%s\r\n", len(options.password), options.password) auth(options.password).Write(conn)
// fmt.Fprintf(conn, "*2\r\n$4\r\nauth\r\n$%d\r\n%s\r\n", len(options.password), options.password)
v, err := readValue(conn) v, err := readValue(conn)
if err != nil { if err != nil {
fmt.Printf("unable to auth: %v\n", err) fmt.Printf("unable to auth: %v\n", err)
@ -67,7 +68,7 @@ func main() {
defer infile.Close() defer infile.Close()
c, e := make(chan value), make(chan error) c, e := make(chan value), make(chan error)
sent := make(chan value, 1) sent := make(chan value)
go streamValues(infile, c, e) go streamValues(infile, c, e)
go func() { go func() {
for { for {

@ -19,6 +19,10 @@ type value interface {
Write(io.Writer) (int, error) Write(io.Writer) (int, error)
} }
func auth(password string) value {
return Array{BulkString("auth"), BulkString(password)}
}
func isOK(v value) bool { func isOK(v value) bool {
vv, ok := v.(String) vv, ok := v.(String)
if !ok { if !ok {

@ -127,18 +127,22 @@ var streamTests = []streamTest{
} }
func (s streamTest) run(t *testing.T) { func (s streamTest) run(t *testing.T) {
in, out := s[0].(string), make([]value, len(s)-1)
for i := 1; i < len(s); i++ {
out[i-1] = s[i].(value)
}
c, e := make(chan value), make(chan error) c, e := make(chan value), make(chan error)
r := strings.NewReader(s[0].(string)) go streamValues(strings.NewReader(in), c, e)
go streamValues(r, c, e) var count int
count := 1
for { for {
select { select {
case v, ok := <-c: case v, ok := <-c:
if !ok { if !ok {
return return
} }
if !eq(s[count], v) { if !eq(out[count], v) {
t.Errorf("expected %q, got %q", s[count], v) t.Errorf("expected %q, got %q", out[count], v)
} }
case err, ok := <-e: case err, ok := <-e:
if !ok { if !ok {

Loading…
Cancel
Save