test that ObjectUrl behaves with various endpoint values

This commit is contained in:
rick 2013-11-05 10:13:28 -07:00 committed by Rick Olson
parent 550c5c7e27
commit 330c8cbfb4
3 changed files with 26 additions and 2 deletions

@ -85,7 +85,7 @@ func doRequest(req *http.Request, creds Creds) (*http.Response, error) {
}
func clientRequest(method, oid string) (*http.Request, Creds, error) {
u := objectUrl(oid)
u := ObjectUrl(oid)
req, err := http.NewRequest(method, u.String(), nil)
if err == nil {
creds, err := credentials(u)
@ -102,7 +102,7 @@ func clientRequest(method, oid string) (*http.Request, Creds, error) {
return req, nil, err
}
func objectUrl(oid string) *url.URL {
func ObjectUrl(oid string) *url.URL {
c := gitmedia.Config()
u, _ := url.Parse(c.Endpoint)
u.Path = filepath.Join(u.Path, "/objects/"+oid)

23
client/client_test.go Normal file

@ -0,0 +1,23 @@
package gitmediaclient
import (
".."
"github.com/bmizerany/assert"
"testing"
)
func TestObjectUrl(t *testing.T) {
oid := "oid"
tests := map[string]string{
"http://example.com": "http://example.com/objects/oid",
"http://example.com/": "http://example.com/objects/oid",
"http://example.com/foo": "http://example.com/foo/objects/oid",
"http://example.com/foo/": "http://example.com/foo/objects/oid",
}
config := gitmedia.Config()
for endpoint, expected := range tests {
config.Endpoint = endpoint
assert.Equal(t, expected, ObjectUrl(oid).String())
}
}

@ -2,4 +2,5 @@ script/fmt
GOPATH="`pwd`/.gopack/vendor" \
go test "$@" \
./queuedir \
./client \
. && script/build