diff --git a/cmd/load_generator_test.go b/cmd/load_generator_test.go index 5237b92..6e81b2c 100644 --- a/cmd/load_generator_test.go +++ b/cmd/load_generator_test.go @@ -38,14 +38,6 @@ func TestWorkerGet(t *testing.T) { }) - ginRouter.POST("/cart", func(c *gin.Context) { - - c.Writer.Header().Set("Content-Type", "application/json") - c.Writer.Write(jsonData) - c.Writer.WriteHeader(http.StatusOK) - - }) - // Create a server using the Gin router ts := httptest.NewServer(ginRouter) defer ts.Close() @@ -59,9 +51,13 @@ func TestWorkerGet(t *testing.T) { } // Update Worker function to use the test server URL - _, err = testGetWorker.Run() + response, err := testGetWorker.Run() // Assertions + if response.ElapsedTime == 0 { + t.Errorf("Expected time grather than 0, got %d", response.ElapsedTime) + } + // compare if error is different to nil or ERROR if err != nil && err != common.ErrorTimeout { @@ -87,9 +83,8 @@ func TestWorkerPost(t *testing.T) { // Create a Gin router for mocking ginRouter := gin.Default() - ginRouter.POST("/cart", func(c *gin.Context) { + ginRouter.POST("/setCurrency", func(c *gin.Context) { - c.Writer.Header().Set("Content-Type", "application/json") c.Writer.Write(jsonData) c.Writer.WriteHeader(http.StatusOK) diff --git a/internal/worker/worker.go b/internal/worker/worker.go index 7ccbdc4..fb47335 100644 --- a/internal/worker/worker.go +++ b/internal/worker/worker.go @@ -58,6 +58,7 @@ func (hw *HttpWorker) Run() (OutputHttpWorker, error) { data, _ = json.Marshal(hw.Body) } if hw.ContentType == "application/x-www-form-urlencoded" { + htmlForm := url.Values{} for key, value := range hw.Body { htmlForm.Set(key, value) @@ -68,7 +69,7 @@ func (hw *HttpWorker) Run() (OutputHttpWorker, error) { } request, err := http.NewRequest(hw.HttpMethod, urlParsed.String(), bytes.NewBuffer(data)) - + request.Header.Set("Content-Type", hw.ContentType) // Validate if error is Timeout or the site is not up if err != nil { log.Fatal("Worker ERROR, creating request:", err)