Skip to content

Commit

Permalink
Change ResolveURL to work as a fmt.Sprintf
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcnunes committed Jul 18, 2017
1 parent 2385ab9 commit 6960e5e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
6 changes: 4 additions & 2 deletions httpfake.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package httpfake

import (
"fmt"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -48,8 +49,9 @@ func (f *HTTPFake) NewHandler() *Request {
}

// ResolveURL resolves the full URL to the fake server for a given path
func (f *HTTPFake) ResolveURL(path string) string {
return f.Server.URL + path
func (f *HTTPFake) ResolveURL(path string, args ...interface{}) string {
format := f.Server.URL + path
return fmt.Sprintf(format, args...)
}

// Reset wipes the request handlers definitions
Expand Down
34 changes: 34 additions & 0 deletions httpfake_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package httpfake

import (
"testing"
)

func TestResolveURL(t *testing.T) {
fakeService := New()
defer fakeService.Server.Close()

testCases := []struct {
resolved string
expected string
}{
{
resolved: fakeService.ResolveURL("/users"),
expected: fakeService.Server.URL + "/users",
},
{
resolved: fakeService.ResolveURL("/users/%v", 1),
expected: fakeService.Server.URL + "/users/1",
},
}

for _, tc := range testCases {
t.Run("ResolveURL", func(t *testing.T) {
if tc.resolved != tc.expected {
t.Errorf("returned unexpected URL: got %v want %v",
tc.resolved, tc.expected)
}
})
}

}

0 comments on commit 6960e5e

Please sign in to comment.