diff options
author | Adrian Villin <avillin@cisco.com> | 2024-08-28 09:34:14 +0200 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2024-11-04 18:07:10 +0000 |
commit | 5a612a4699c6347296d7a6e5d4704a2108cc6a65 (patch) | |
tree | baf2e6691762a3362fcadcf5ec7e8f6a1321baa6 /extras/hs-test | |
parent | afce28764522fcc6c94f9ebbbc580fcd1250b63d (diff) |
hsa: added GET method to client
Type: improvement
Change-Id: I46f7e1e2b509a463ff4b2492bf6412b67a1afdc4
Signed-off-by: Adrian Villin <avillin@cisco.com>
Diffstat (limited to 'extras/hs-test')
-rw-r--r-- | extras/hs-test/http_test.go | 102 |
1 files changed, 93 insertions, 9 deletions
diff --git a/extras/hs-test/http_test.go b/extras/hs-test/http_test.go index 7d0063d7540..0e5d7e655be 100644 --- a/extras/hs-test/http_test.go +++ b/extras/hs-test/http_test.go @@ -10,6 +10,7 @@ import ( "net/http/httptrace" "os" "strconv" + "strings" "sync" "time" @@ -30,9 +31,10 @@ func init() { HttpContentLengthTest, HttpStaticBuildInUrlGetIfListTest, HttpStaticBuildInUrlGetVersionTest, HttpStaticMacTimeTest, HttpStaticBuildInUrlGetVersionVerboseTest, HttpVersionNotSupportedTest, HttpInvalidContentLengthTest, HttpInvalidTargetSyntaxTest, HttpStaticPathTraversalTest, HttpUriDecodeTest, - HttpHeadersTest, HttpStaticFileHandlerTest, HttpStaticFileHandlerDefaultMaxAgeTest, HttpClientTest, HttpClientErrRespTest, HttpClientPostFormTest, - HttpClientPostFileTest, HttpClientPostFilePtrTest, HttpUnitTest, HttpRequestLineTest, - HttpStaticFileHandlerWrkTest, HttpStaticUrlHandlerWrkTest, HttpConnTimeoutTest) + HttpHeadersTest, HttpStaticFileHandlerTest, HttpStaticFileHandlerDefaultMaxAgeTest, HttpClientTest, + HttpClientErrRespTest, HttpClientPostFormTest, HttpClientGet128kbResponseTest, HttpClientGetResponseBodyTest, + HttpClientGetNoResponseBodyTest, HttpClientPostFileTest, HttpClientPostFilePtrTest, HttpUnitTest, + HttpRequestLineTest, HttpClientGetTimeout, HttpStaticFileHandlerWrkTest, HttpStaticUrlHandlerWrkTest, HttpConnTimeoutTest) RegisterNoTopoSoloTests(HttpStaticPromTest, HttpGetTpsTest, HttpGetTpsInterruptModeTest, PromConcurrentConnectionsTest, PromMemLeakTest, HttpClientPostMemLeakTest, HttpInvalidClientRequestMemLeakTest, HttpPostTpsTest, HttpPostTpsInterruptModeTest, PromConsecutiveConnectionsTest) @@ -168,7 +170,6 @@ func HttpPersistentConnectionTest(s *NoTopoSuite) { s.Log(o2) s.AssertContains(o2, "ESTABLISHED") s.AssertEqual(o1, o2) - } func HttpPipeliningTest(s *NoTopoSuite) { @@ -196,7 +197,7 @@ func HttpPipeliningTest(s *NoTopoSuite) { s.AssertNil(err, fmt.Sprint(err)) s.AssertEqual(n, len([]rune(req2))) reply := make([]byte, 1024) - n, err = conn.Read(reply) + _, err = conn.Read(reply) s.AssertNil(err, fmt.Sprint(err)) s.Log(string(reply)) s.AssertContains(string(reply), "delayed data", "first request response not received") @@ -297,6 +298,7 @@ func HttpClientPostFormTest(s *NoTopoSuite) { s.LogHttpReq(true), ghttp.VerifyRequest("POST", "/test"), ghttp.VerifyContentType("application/x-www-form-urlencoded"), + ghttp.VerifyHeaderKV("Hello", "World"), ghttp.VerifyBody([]byte(body)), ghttp.RespondWith(http.StatusOK, nil), )) @@ -305,10 +307,92 @@ func HttpClientPostFormTest(s *NoTopoSuite) { uri := "http://" + serverAddress + "/80" vpp := s.GetContainerByName("vpp").VppInstance - o := vpp.Vppctl("http post uri " + uri + " target /test data " + body) + o := vpp.Vppctl("http client post verbose header Hello:World uri " + uri + " target /test data " + body) + + s.Log(o) + s.AssertContains(o, "200 OK") +} + +func HttpClientGetResponseBodyTest(s *NoTopoSuite) { + response := "<body>hello world</body>" + size := len(response) + httpClientGet(s, response, size) +} +func HttpClientGet128kbResponseTest(s *NoTopoSuite) { + response := strings.Repeat("a", 128*1024) + size := len(response) + httpClientGet(s, response, size) +} + +func HttpClientGetNoResponseBodyTest(s *NoTopoSuite) { + response := "" + httpClientGet(s, response, 0) +} + +func httpClientGet(s *NoTopoSuite, response string, size int) { + serverAddress := s.HostAddr() + vpp := s.GetContainerByName("vpp").VppInstance + + server := ghttp.NewUnstartedServer() + l, err := net.Listen("tcp", serverAddress+":80") + s.AssertNil(err, fmt.Sprint(err)) + server.HTTPTestServer.Listener = l + server.AppendHandlers( + ghttp.CombineHandlers( + s.LogHttpReq(false), + ghttp.VerifyRequest("GET", "/test"), + ghttp.VerifyHeaderKV("Hello", "World"), + ghttp.VerifyHeaderKV("Test-H2", "Test-K2"), + ghttp.RespondWith(http.StatusOK, string(response), http.Header{"Content-Length": {strconv.Itoa(size)}}), + )) + server.Start() + defer server.Close() + + uri := "http://" + serverAddress + "/80" + cmd := "http client use-ptr verbose header Hello:World header Test-H2:Test-K2 save-to response.txt uri " + uri + " target /test" + + o := vpp.Vppctl(cmd) + outputLen := len(o) + if outputLen > 500 { + s.Log(o[:500]) + s.Log("* HST Framework: output limited to 500 chars to avoid flooding the console. Output length: " + fmt.Sprint(outputLen)) + } else { + s.Log(o) + } + s.AssertContains(o, "200 OK") + s.AssertContains(o, response) + s.AssertContains(o, "Content-Length: "+strconv.Itoa(size)) + + file_contents := vpp.Container.Exec(false, "cat /tmp/response.txt") + s.AssertContains(file_contents, response) +} + +func HttpClientGetTimeout(s *NoTopoSuite) { + serverAddress := s.HostAddr() + vpp := s.GetContainerByName("vpp").VppInstance + + server := ghttp.NewUnstartedServer() + l, err := net.Listen("tcp", serverAddress+":"+s.GetPortFromPpid()) + s.AssertNil(err, fmt.Sprint(err)) + server.HTTPTestServer.Listener = l + server.AppendHandlers( + ghttp.CombineHandlers( + s.LogHttpReq(false), + ghttp.VerifyRequest("GET", "/timeout"), + http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + time.Sleep(5 * time.Second) + }), + ghttp.RespondWith(http.StatusOK, nil), + )) + server.Start() + defer server.Close() + uri := "http://" + serverAddress + "/" + s.GetPortFromPpid() + cmd := "http client verbose timeout 1 uri " + uri + " target /timeout" + + o := vpp.Vppctl(cmd) s.Log(o) - s.AssertNotContains(o, "error") + s.AssertContains(o, "error: timeout") } func httpClientPostFile(s *NoTopoSuite, usePtr bool, fileSize int) { @@ -334,14 +418,14 @@ func httpClientPostFile(s *NoTopoSuite, usePtr bool, fileSize int) { defer server.Close() uri := "http://" + serverAddress + "/80" - cmd := "http post uri " + uri + " target /test file " + fileName + cmd := "http client post verbose uri " + uri + " target /test file " + fileName if usePtr { cmd += " use-ptr" } o := vpp.Vppctl(cmd) s.Log(o) - s.AssertNotContains(o, "error") + s.AssertContains(o, "200 OK") } func HttpClientPostFileTest(s *NoTopoSuite) { |