First part of parsing settings client-side

This commit is contained in:
Daniel Smith
2014-06-12 12:37:35 -07:00
parent 5b3c6f1965
commit 881613e3f5
5 changed files with 139 additions and 4 deletions

View File

@@ -17,7 +17,6 @@ package util
import (
"io/ioutil"
"log"
"net/http"
)
@@ -26,12 +25,18 @@ import (
type TestInterface interface {
Errorf(format string, args ...interface{})
}
type LogInterface interface {
Logf(format string, args ...interface{})
}
// FakeHandler is to assist in testing HTTP requests.
type FakeHandler struct {
RequestReceived *http.Request
StatusCode int
ResponseBody string
// For logging - you can use a *testing.T
// This will keep log messages associated with the test.
T LogInterface
}
func (f *FakeHandler) ServeHTTP(response http.ResponseWriter, request *http.Request) {
@@ -40,8 +45,8 @@ func (f *FakeHandler) ServeHTTP(response http.ResponseWriter, request *http.Requ
response.Write([]byte(f.ResponseBody))
bodyReceived, err := ioutil.ReadAll(request.Body)
if err != nil {
log.Printf("Received read error: %#v", err)
if err != nil && f.T != nil {
f.T.Logf("Received read error: %#v", err)
}
f.ResponseBody = string(bodyReceived)
}