chore: add basic proxy test
Cadoles/go-proxy/pipeline/head This commit looks good Details

This commit is contained in:
wpetit 2023-04-24 20:14:31 +02:00
parent 56b7434498
commit 6ed3db5f69
1 changed files with 38 additions and 0 deletions

38
proxy_test.go Normal file
View File

@ -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")
}
}