forked from fjl/go-couchdb
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathhttp_test.go
50 lines (43 loc) · 1.04 KB
/
http_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package couchdb
import (
"net/http"
"testing"
)
type testauth struct{ called bool }
func (a *testauth) AddAuth(*http.Request) {
a.called = true
}
func TestClientSetAuth(t *testing.T) {
c := newTestClient(t)
c.Handle("HEAD /", func(resp http.ResponseWriter, req *http.Request) {})
auth := new(testauth)
c.SetAuth(auth)
if err := c.Ping(); err != nil {
t.Fatal(err)
}
if !auth.called {
t.Error("AddAuth was not called")
}
auth.called = false
c.SetAuth(nil)
if err := c.Ping(); err != nil {
t.Fatal(err)
}
if auth.called {
t.Error("AddAuth was called after removing Auth instance")
}
}
func TestPath(t *testing.T) {
data := map[string][]string {
// Expected output Input
"/foo/bar/baz": []string{"foo","bar","baz"},
"/foo/_design/bar/_view/baz": []string{"foo","_design/bar","_view","baz"},
"/foo%2Fbar/baz%2Fquz": []string{"foo/bar","baz/quz"},
}
for expected,segs := range data {
result := path(segs...)
if result != expected {
t.Fatalf("path() produced '%s', expected '%s'", result, expected)
}
}
}