From e2349b1d2df3a7175cfac5417a68cff01da38647 Mon Sep 17 00:00:00 2001 From: nothinux Date: Sat, 2 Oct 2021 22:10:05 +0700 Subject: [PATCH] add test live response --- .../offlinehttp/read_response_test.go | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/v2/pkg/protocols/offlinehttp/read_response_test.go b/v2/pkg/protocols/offlinehttp/read_response_test.go index 80086a0c..4a75d726 100644 --- a/v2/pkg/protocols/offlinehttp/read_response_test.go +++ b/v2/pkg/protocols/offlinehttp/read_response_test.go @@ -2,7 +2,10 @@ package offlinehttp import ( "io/ioutil" + "net/http" + "net/http/httputil" "testing" + "time" "github.com/stretchr/testify/require" ) @@ -149,4 +152,26 @@ Server: Google Frontend require.Equal(t, "Google Frontend", resp.Header.Get("Server"), "could not get correct headers") }) } + + t.Run("test-live-response-with-content-length", func(t *testing.T) { + client := &http.Client{ + Timeout: 3 * time.Second, + } + + data, err := client.Get("https://golang.org/doc/install") + require.Nil(t, err, "could not dial url") + defer data.Body.Close() + + b, err := httputil.DumpResponse(data, true) + require.Nil(t, err, "could not dump response") + + respData, err := readResponseFromString(string(b)) + require.Nil(t, err, "could not read response from string") + + _, err = ioutil.ReadAll(respData.Body) + require.Nil(t, err, "could not read response body") + + require.Equal(t, "Google Frontend", respData.Header.Get("Server"), "could not get correct headers") + + }) }