William Petit
e2dc3e1a03
All checks were successful
Cadoles/go-proxy/pipeline/head This commit looks good
39 lines
715 B
Go
39 lines
715 B
Go
package proxy
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func TestProxy(t *testing.T) {
|
|
res := httptest.NewRecorder()
|
|
req, err := http.NewRequest("GET", "http://example.com", nil)
|
|
if err != nil {
|
|
t.Fatalf("%+v", errors.WithStack(err))
|
|
}
|
|
|
|
proxy := New()
|
|
|
|
proxy.ServeHTTP(res, req)
|
|
|
|
if e, g := http.StatusOK, res.Code; e != g {
|
|
t.Errorf("res.Code: expected '%v', got '%v'", e, g)
|
|
}
|
|
|
|
body, err := ioutil.ReadAll(res.Body)
|
|
if err != nil {
|
|
t.Errorf("%+v", errors.WithStack(err))
|
|
}
|
|
|
|
marker := "<title>Example Domain</title>"
|
|
|
|
if !strings.Contains(string(body), marker) {
|
|
t.Errorf("could not find expected marker in response body")
|
|
}
|
|
}
|