From 6ed3db5f69e99cb2df01f89d22746c6170acb7a0 Mon Sep 17 00:00:00 2001 From: William Petit Date: Mon, 24 Apr 2023 20:14:31 +0200 Subject: [PATCH] chore: add basic proxy test --- proxy_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 proxy_test.go diff --git a/proxy_test.go b/proxy_test.go new file mode 100644 index 0000000..3f4d4b5 --- /dev/null +++ b/proxy_test.go @@ -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 := "Example Domain" + + if !strings.Contains(string(body), marker) { + t.Errorf("could not find expected marker in response body") + } +}