@@ -2,6 +2,8 @@ package request_test
22
33import (
44 stdCtx "context"
5+ "net/http"
6+ "net/http/httptest"
57 "os"
68 "path/filepath"
79 "testing"
@@ -61,10 +63,25 @@ var _ = Describe("Request Runner", func() {
6163 })
6264
6365 Describe ("Exec" , func () {
66+ var testServer * httptest.Server
67+ BeforeEach (func () {
68+ testServer = httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
69+ if r .Method == http .MethodGet {
70+ w .WriteHeader (http .StatusOK )
71+ w .Write ([]byte (`{"message": "GET request successful"}` ))
72+ } else if r .Method == http .MethodPost {
73+ w .WriteHeader (http .StatusOK )
74+ w .Write ([]byte (`{"key": "value"}` ))
75+ } else {
76+ http .Error (w , "Method not allowed" , http .StatusMethodNotAllowed )
77+ }
78+ }))
79+ })
80+
6481 It ("should send a GET request and log the response" , func () {
6582 exec := & executable.Executable {
6683 Request : & executable.RequestExecutableType {
67- URL : "https://httpbin.org/get" ,
84+ URL : testServer . URL ,
6885 Method : executable .RequestExecutableTypeMethodGET ,
6986 LogResponse : true ,
7087 },
@@ -78,7 +95,7 @@ var _ = Describe("Request Runner", func() {
7895 It ("should send a POST request with a body and log the response" , func () {
7996 exec := & executable.Executable {
8097 Request : & executable.RequestExecutableType {
81- URL : "https://httpbin.org/post" ,
98+ URL : testServer . URL ,
8299 Method : executable .RequestExecutableTypeMethodPOST ,
83100 Body : `{"key": "value"}` ,
84101 LogResponse : true ,
@@ -93,7 +110,7 @@ var _ = Describe("Request Runner", func() {
93110 It ("should save the response to a file" , func () {
94111 exec := & executable.Executable {
95112 Request : & executable.RequestExecutableType {
96- URL : "https://httpbin.org/get" ,
113+ URL : testServer . URL ,
97114 Method : executable .RequestExecutableTypeMethodGET ,
98115 ResponseFile : & executable.RequestResponseFile {
99116 Filename : "response.json" ,
@@ -115,14 +132,14 @@ var _ = Describe("Request Runner", func() {
115132 It ("should transform the response when specified" , func () {
116133 exec := & executable.Executable {
117134 Request : & executable.RequestExecutableType {
118- URL : "https://httpbin.org/get" ,
135+ URL : testServer . URL ,
119136 Method : executable .RequestExecutableTypeMethodGET ,
120137 TransformResponse : `upper(body)` ,
121138 LogResponse : true ,
122139 },
123140 }
124141
125- ctx .Logger .EXPECT ().Infox (gomock .Any (), gomock .Any (), gomock .Regex ("HTTPS://HTTPBIN.ORG " )).Times (1 )
142+ ctx .Logger .EXPECT ().Infox (gomock .Any (), gomock .Any (), gomock .Regex ("SUCCESSFUL " )).Times (1 )
126143 err := requestRnr .Exec (ctx .Ctx , exec , mockEngine , make (map [string ]string ), nil )
127144 Expect (err ).NotTo (HaveOccurred ())
128145 })
0 commit comments