Skip to content
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

Added FORM to Lama2 #39

Merged
merged 13 commits into from
Oct 10, 2023
Merged

Added FORM to Lama2 #39

merged 13 commits into from
Oct 10, 2023

Conversation

RijulTP
Copy link
Contributor

@RijulTP RijulTP commented Oct 1, 2023

What type of MR is this? (check all applicable)

  • πŸ• Feature
  • πŸ› Bug Fix
  • πŸ“ Doc Update
  • 🎨 Style
  • πŸ§‘β€πŸ’» Code Refactor
  • πŸ”₯ Performance Improvements
  • βœ… Test
  • πŸ€– Build
  • πŸ” CI
  • ⏩ Revert

Description

This MR adds FORM to lama2
Solves: #29

Important files to start review from

  • cmdgen.go
  • lama2parser.go
  • varjson.go

Added tests?

  • πŸ‘ yes
  • πŸ™… no, because they aren't needed
  • πŸ™‹ no, because I need help

Added to documentation?

If documentation update is there then run make mkdocs once PR is in acceptable state.

  • πŸ““ make mkdocs
  • πŸ“œ README.md
  • πŸ™… no documentation needed

@RijulTP RijulTP marked this pull request as ready for review October 2, 2023 05:27
@shrsv
Copy link
Contributor

shrsv commented Oct 2, 2023

Solves: #29

cmdgen/cmdgen.go Outdated
@@ -76,6 +77,12 @@ func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, header
}
}

if form {
for key, val := range jsonObj.Data().(*gabs.Container).ChildrenMap() {
command = append(command, "'"+key+"'='"+val.Data().(string)+"' ")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use fmt.Sprintf to make it more readable.

cmdgen/cmdgen.go Outdated
@@ -107,7 +114,12 @@ func ConstructCommand(parsedInput *gabs.Container, o *lama2cmd.Opts) ([]string,
if multipart != nil {
multipartBool = true
}
form := parsedInput.S("form","value")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you run gofumpt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make lint and make gofumpt

@shrsv
Copy link
Contributor

shrsv commented Oct 2, 2023

Should add at least a positive & negative test/example, and demonstrate results is as expected.

Check https://github.com/HexmosTech/Lama2/blob/main/tests/lama2_test.go#L70

cmdgen/cmdgen.go Outdated
@@ -107,7 +115,12 @@ func ConstructCommand(parsedInput *gabs.Container, o *lama2cmd.Opts) ([]string,
if multipart != nil {
multipartBool = true
}
form := parsedInput.S("form", "value")
formBool := false
if form != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not do a direct comparison for a bool? (if needed through after casts)

pair, e1 := p.Match([]string{"VarJSONPair"})
if e1 != nil && !hasMultipart {
if e1 != nil && (!hasMultipart || !hasForm) {
Copy link
Contributor

@shrsv shrsv Oct 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can simplify condition. What are we checking for here?

!a || !b = !(a && b)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

image

If either a or b is false, then the result is true.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a comment explaining the whole thing with simplification.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When i rechecked that part, Since FORM does not have file upload, the condition is not needed, since that condition is for erroring out in the event where there is no key value pairs.

multipart has files so it can be executed even without key value pairs, so that's why that condition is there only for multipart

@@ -52,6 +52,6 @@ func Prettify(parsedAPI *gabs.Container, context map[string]bool, markRange map[
}

res2 := utils.RemoveUnquotedMarker(content)
os.WriteFile(fPath, []byte(res2), 0644)
os.WriteFile(fPath, []byte(res2), 0o644)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change needed?

According to Go By Example, no.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It came up when i ran make gofumpt

testutils "github.com/HexmosTech/lama2/tests/utils"
)

func TestFormPositive(t *testing.T) {
Copy link
Contributor

@shrsv shrsv Oct 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we verified none of the MULTIPART cases are breaking?

Just verify how postman deals with a multipart without file attachment once. I think we should verify that case works (if a testcase not there, we can add that as well).

@shrsv shrsv merged commit fd6f099 into main Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants