UtpMahesh
UtpMahesh

Reputation: 410

pass a string array from gatling CSV feeder

Is it possible to pass the string array from feeder to post requests.

my csv file :

sourceId,date,keywords,payload
stg_st_record1,"2017-10-10T00:53:42Z",["SAVE_ALL","John","configs"],"Here is some payload1"
stg_st_record2,"2017-10-10T00:53:42Z",["SAVE_ALL","John","configs"],"Here is some payload2"

my gatling script

def PostActionLog():ChainBuilder = {
repeat(times = 10) {
feed(csvPostFeeder)
.exec (http("Post Action logs")
.post("/api/actionlogs")
.body(StringBody("""{"sourceId": "${sourceId}","date": "${date}", "keywords": ${keywords}, 
 "payload": "${payload}" }"""))
.check(status.is(201)))
 }
}

The error message I am receiving :

byteArraysBody={"sourceId": "stg_st_record2","date": "2017-10-10T00:53:42Z", "keywords": 
 ["SAVE_ALL", "payload": "John" }

 HTTP response:
 status=
 415 Unsupported Media Type
 headers= 
 Content-Type: application/json; charset=utf-8
 Date: Wed, 25 Mar 2020 17:05:24 GMT
 Server: Kestrel
 Content-Length: 147

Seems like Gatling does not receiving the feeder data correctly, I guess breaking point is the way that string array values pass to gatling post request, Is there a way to achieve this ?

Upvotes: 0

Views: 1438

Answers (1)

Stéphane LANDELLE
Stéphane LANDELLE

Reputation: 6600

The problem is your file is very malformed CSV. CSV has a spec: RFC4180.

  1. If comma is the separator, if a comma character is inside a value, the value must be wrapped with double quotes.
  2. If a double quote character is inside a wrapped value, it must be escaped with a preceding double quote.
sourceId,date,keywords,payload
stg_st_record1,"2017-10-10T00:53:42Z","[""SAVE_ALL"",""John"",""configs""]","Here is some payload1"
stg_st_record2,"2017-10-10T00:53:42Z","[""SAVE_ALL"",""John"",""configs""]","Here is some payload2"

Upvotes: 1

Related Questions