From 1740f13db8b5b25a41cdabc397706be5aad9c219 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Wed, 6 Aug 2014 15:40:38 +0000 Subject: [PATCH] fix unit tests --- rsload.go | 5 +++-- values.go | 4 ++++ values_test.go | 14 +++++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/rsload.go b/rsload.go index 8f615ed..23eb5ba 100644 --- a/rsload.go +++ b/rsload.go @@ -47,7 +47,8 @@ func main() { defer conn.Close() 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) if err != nil { fmt.Printf("unable to auth: %v\n", err) @@ -67,7 +68,7 @@ func main() { defer infile.Close() c, e := make(chan value), make(chan error) - sent := make(chan value, 1) + sent := make(chan value) go streamValues(infile, c, e) go func() { for { diff --git a/values.go b/values.go index f74ed8c..c9c4c5d 100644 --- a/values.go +++ b/values.go @@ -19,6 +19,10 @@ type value interface { Write(io.Writer) (int, error) } +func auth(password string) value { + return Array{BulkString("auth"), BulkString(password)} +} + func isOK(v value) bool { vv, ok := v.(String) if !ok { diff --git a/values_test.go b/values_test.go index 9f105b2..ae0f347 100644 --- a/values_test.go +++ b/values_test.go @@ -127,18 +127,22 @@ var streamTests = []streamTest{ } 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) - r := strings.NewReader(s[0].(string)) - go streamValues(r, c, e) - count := 1 + go streamValues(strings.NewReader(in), c, e) + var count int for { select { case v, ok := <-c: if !ok { return } - if !eq(s[count], v) { - t.Errorf("expected %q, got %q", s[count], v) + if !eq(out[count], v) { + t.Errorf("expected %q, got %q", out[count], v) } case err, ok := <-e: if !ok {