Skip to content

Commit

Permalink
Moved tests for changes related stuff to changes_test
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin committed Dec 5, 2013
1 parent 756f05e commit d0714f2
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 74 deletions.
80 changes: 80 additions & 0 deletions changes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package couch

import (
"io"
"testing"
"time"
)

type testRC struct {
bytes, reads int
err error
}

func (t *testRC) Read(b []byte) (int, error) {
t.reads++
t.bytes += len(b)
return len(b), t.err
}

func (t *testRC) Close() error {
t.err = io.EOF
return nil
}

type testDeadliner int

func (t *testDeadliner) SetReadDeadline(time.Time) error {
*t++
return nil
}

func TestTimeoutClient(t *testing.T) {
trc := &testRC{}
var td testDeadliner
tc := timeoutClient{trc, &td, 13}
buf := make([]byte, 4096)

_, err := tc.Read(buf)
if err != nil {
t.Fatalf("Failed first read: %v", err)
}
tc.Close()
_, err = tc.Read(buf)
if err == nil {
t.Fatalf("Didn't fail second read")
}

if trc.reads != 2 || trc.bytes != 8192 {
t.Errorf("Expected %v reads at %v bytes, got %v / %v",
2, 8912, trc.reads, trc.bytes)
}
}

func TestI64Opt(t *testing.T) {
m := map[string]interface{}{
"a": 1,
"b": int64(2),
"c": 3.14,
"d": "4",
"e": "five",
"f": TestI64Opt,
}

tests := map[string]int64{
"a": 1,
"b": 2,
"c": 3,
"d": 4,
"e": 99,
"f": 99,
}

for k, exp := range tests {
got := i64defopt(m, k, 99)
if got != exp {
t.Errorf("Expected %v for %v (%v), got %v",
exp, k, m[k], got)
}
}
}
74 changes: 0 additions & 74 deletions couch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"reflect"
"strings"
"testing"
"time"
)

func TestHttpError(t *testing.T) {
Expand Down Expand Up @@ -369,79 +368,6 @@ func TestURLs(t *testing.T) {
}
}

type testRC struct {
bytes, reads int
err error
}

func (t *testRC) Read(b []byte) (int, error) {
t.reads++
t.bytes += len(b)
return len(b), t.err
}

func (t *testRC) Close() error {
t.err = io.EOF
return nil
}

type testDeadliner int

func (t *testDeadliner) SetReadDeadline(time.Time) error {
*t++
return nil
}

func TestTimeoutClient(t *testing.T) {
trc := &testRC{}
var td testDeadliner
tc := timeoutClient{trc, &td, 13}
buf := make([]byte, 4096)

_, err := tc.Read(buf)
if err != nil {
t.Fatalf("Failed first read: %v", err)
}
tc.Close()
_, err = tc.Read(buf)
if err == nil {
t.Fatalf("Didn't fail second read")
}

if trc.reads != 2 || trc.bytes != 8192 {
t.Errorf("Expected %v reads at %v bytes, got %v / %v",
2, 8912, trc.reads, trc.bytes)
}
}

func TestI64Opt(t *testing.T) {
m := map[string]interface{}{
"a": 1,
"b": int64(2),
"c": 3.14,
"d": "4",
"e": "five",
"f": TestI64Opt,
}

tests := map[string]int64{
"a": 1,
"b": 2,
"c": 3,
"d": 4,
"e": 99,
"f": 99,
}

for k, exp := range tests {
got := i64defopt(m, k, 99)
if got != exp {
t.Errorf("Expected %v for %v (%v), got %v",
exp, k, m[k], got)
}
}
}

func TestMust(t *testing.T) {
must(nil) // no panic
panicked := false
Expand Down

0 comments on commit d0714f2

Please sign in to comment.