Skip to content

Refactor getBrowserNameByOS#19

Closed
Xercoy wants to merge 2 commits intoBunchhieng:masterfrom
Xercoy:refactor-and-add-unit-tests
Closed

Refactor getBrowserNameByOS#19
Xercoy wants to merge 2 commits intoBunchhieng:masterfrom
Xercoy:refactor-and-add-unit-tests

Conversation

@Xercoy
Copy link
Copy Markdown

@Xercoy Xercoy commented Oct 5, 2018

getBrowserNameByOS doesn't have unit tests, so I decided to add one.

Right now, it's basically a subtest that runs based on the value of runtime.GOOS since the way getBrowserNameByOS is written is only meant to handle cases where we're dealing with a darwin based OS. Not only does the unit test do that, but it tests every possible denormalized string value.

I was thinking that since the function only handles cases for a darwin OS, we can ensure that any other value for runtime.GOOS will result in a return value of a null string. While it does adhere to the current behavior, I feel like it could be overkill.

The code for it also seemed like it could have been simplified a bit for a few reasons:

  • variable name 'k' for the sole string argument didn't seem like it provided any context as to what the argument was
  • doubly nested switch, case blocks for basic logic just seemed like it could be simplified.

To ensure that my changes to the function work as intended, I created the test, ran the entire test suite and ensured it passed, modified getBrowserNameByOS, then ran tests a final time to ensure its behavior remained unchanged.

Copy link
Copy Markdown
Owner

@Bunchhieng Bunchhieng left a comment

Choose a reason for hiding this comment

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

Looks good. Feel free to modify the checkOS method to support Windows or Linux in this PR or I can add a follow-up issue to address it. Thanks

- [Fatih Arslan](https://github.com/fatih/color)
- [Martin Angers](https://github.com/PuerkitoBio/goquery)
- [skratchdot](https://github.com/skratchdot/open-golang)
- [Corey Prak](https://www.instagram.com/prakattak/)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This section is mainly for the dependencies I use on the project. Your name will show up in the release. 👍

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Ah, definitely. I'll add a credit to stretchr maybe?

"brave": "Brave",
}

if os == "darwin" {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I was thinking if we can refactor this to support Windows and Linux.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That sounds good - would the denormalized values be anything different?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I add this issue. there is a list of all the OS name. the browser string may be vary between each OS.
#21

@Bunchhieng
Copy link
Copy Markdown
Owner

Would you be able to fix the merge conflict? @Xercoy

@Xercoy
Copy link
Copy Markdown
Author

Xercoy commented Oct 8, 2018

@Bunchhieng I'll work on it and ping you when it's done. Apologies for the delay.

@Xercoy
Copy link
Copy Markdown
Author

Xercoy commented Oct 21, 2018

closing in favor of #50

@Xercoy Xercoy closed this Oct 21, 2018
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.

2 participants