chore: add basic proxy test
Cadoles/go-proxy/pipeline/head This commit looks good
Details
Cadoles/go-proxy/pipeline/head This commit looks good
Details
This commit is contained in:
parent
56b7434498
commit
6ed3db5f69
|
@ -0,0 +1,38 @@
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue