-
-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add curl command in yaml #929
feat: add curl command in yaml #929
Conversation
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please resolve these comments
pkg/util.go
Outdated
curl := fmt.Sprintf("curl --request %s \\\n", method) | ||
curl = curl + fmt.Sprintf(" --url %s \\\n", url) | ||
for k, v := range header { | ||
if k == "Content-Length" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you debugged why providing content-length in curl is throwing an error when you use the curl..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@charankamarapu I found the issue. It is happening because of the extra spaces before "url" field of --data.
with extra space | without extra space |
---|---|
![]() |
![]() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok then try to find out why there is an extra space and remove it. Add content-length header also in the the curl.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, I guess keeping curl in top level field looks fine for me. Because curl section shouldn't be under spec, as spec majorly tells how keploy decoded its req and resp. Put the curl section before spec or may be at the last. Btw great work in analysing the bug.
@@ -132,3 +132,16 @@ func GenerateRandomID() int { | |||
id := rand.Intn(1000000000) // Adjust the range as needed | |||
return id | |||
} | |||
|
|||
func MakeCurlCommand(method string, url string, header map[string]string, body string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add checks for param and type of methods . Like if there is a body then only you need to add --body
etc . These kind of checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@charankamarapu I have added a body check in makeCurlCommand like this :
any invalid method type would result in 400 error and it won't make a .yaml file and also makeCurlCommand function won't be called
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok got it.
@@ -132,3 +132,16 @@ func GenerateRandomID() int { | |||
id := rand.Intn(1000000000) // Adjust the range as needed | |||
return id | |||
} | |||
|
|||
func MakeCurlCommand(method string, url string, header map[string]string, body string) string { | |||
curl := fmt.Sprintf("curl --request %s \\\n", method) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling.
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
@charankamarapu At any level at least 4 spaces will always be present: |
I guess there is no other way . Yes do it as eariler. |
Signed-off-by: Akash Kumar <meakash7902@gmail.com>
Hi @AkashKumar7902 are all changes done can I review the PR..? |
@charankamarapu yeah |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ship it!
Related Issue
Closes: #881
Describe the changes you've made
I have added a new entry in HttpReq struct named
Curl
in which string representation of curl command will be stored. I have defined a function namedmakeCurlCommand
to get the string representation of the curl commandType of change
Please let us know if any test cases are added
Please describe the tests(if any). Provide instructions how its affecting the coverage.
Describe if there is any unusual behaviour of your code(Write
NA
if there isn't)N/A
Checklist:
Screenshots (if any)