Skip to content

Commit

Permalink
fix missed content-type setter
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel rivera authored and daniel rivera committed Apr 29, 2024
1 parent dc57ce2 commit 97cacd2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
17 changes: 6 additions & 11 deletions cmd/load_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 {
Expand All @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion internal/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 97cacd2

Please sign in to comment.