Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Stay up to update with new technology and waste all your morning reading everyth
- [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?


#### License

Expand Down
43 changes: 22 additions & 21 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ const (
)

// Colors for console output
var blue = color.New(color.FgBlue, color.Bold).SprintFunc()
var yellow = color.New(color.FgYellow, color.Bold).SprintFunc()
var red = color.New(color.FgRed, color.Bold).SprintFunc()
var (
blue = color.New(color.FgBlue, color.Bold).SprintFunc()
yellow = color.New(color.FgYellow, color.Bold).SprintFunc()
red = color.New(color.FgRed, color.Bold).SprintFunc()
)

type logWriter struct{}

Expand Down Expand Up @@ -223,27 +225,26 @@ func findBrowser(target string) string {
}

// getBrowserNameByOS normilizes browser name
func getBrowserNameByOS(k string) string {
browser := ""
switch k {
case "google", "chrome":
switch runtime.GOOS {
case "darwin":
browser = "Google Chrome"
}
case "mozilla", "firefox":
switch runtime.GOOS {
case "darwin":
browser = "Firefox"
}
case "brave":
switch runtime.GOOS {
case "darwin":
browser = "Brave"
func getBrowserNameByOS(denormalizedStr string) string {
os := runtime.GOOS

// key = denormalized value, value = normalized value
browserNameMap := map[string]string{
"google": "Google Chrome",
"chrome": "Google Chrome",
"mozilla": "Firefox",
"firefox": "Firefox",
"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

normalizedStr, ok := browserNameMap[denormalizedStr]
if ok {
return normalizedStr
}
}

return browser
return ""
}

// checkGoPath checks for GOPATH
Expand Down
23 changes: 23 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"log"
"reflect"
"runtime"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -47,3 +48,25 @@ func TestGetLobstersStories(t *testing.T) {
assert.NotNil(t, news)
assert.Equal(t, 10, len(news), "They should be equal")
}

func TestGetBrowserNameByOS(t *testing.T) {
// For now, getBrowserName only assumes the logic below
// applies to the darwin OS; add subtests as more os values
// are added.
if runtime.GOOS == "darwin" {
t.Run("Validate Darwin OS", func(t *testing.T) {
browserNameMap := map[string][]string{
"Google Chrome": []string{"google", "chrome"},
"Firefox": []string{"mozilla", "firefox"},
"Brave": []string{"brave"},
}

// test every possible browser string value
for normalizedStr, browserStrSlice := range browserNameMap {
for _, browserStr := range browserStrSlice {
assert.Equal(t, getBrowserNameByOS(browserStr), normalizedStr)
}
}
})
}
}