Support body rewrite
This commit is contained in:
@@ -1,3 +1,42 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type fakeTransport struct{}
|
||||
|
||||
func (ft fakeTransport) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||
return &http.Response{
|
||||
Body: r.Body,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// empty url -> OK //TODO
|
||||
func TestRewrite(t *testing.T) {
|
||||
transport := &rewrite{
|
||||
rewrites: map[string]string{
|
||||
"a": "b",
|
||||
},
|
||||
baseTransport: fakeTransport{},
|
||||
}
|
||||
|
||||
r, err := http.NewRequest("GET", "asdf", strings.NewReader("mary had a little lamb"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
resp, err := transport.RoundTrip(r)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(b) != "mbry hbd b little lbmb" {
|
||||
t.Errorf("failed to replace: got %q, want \"b\"", b)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user