Skip to content

Commit

Permalink
Merge pull request #135 from nao1215/chore/update-test-and-doc
Browse files Browse the repository at this point in the history
Update README and unit test
  • Loading branch information
nao1215 authored Mar 23, 2024
2 parents 7f46f0d + b2aeca4 commit 117823e
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 12 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@
"contributions": [
"code"
]
},
{
"login": "rkscv",
"name": "rkscv",
"avatar_url": "https://avatars.githubusercontent.com/u/155284493?v=4",
"profile": "https://github.com/rkscv",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
9 changes: 0 additions & 9 deletions Contributors.md

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-8-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-9-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)
[![MultiVersionUnitTest](https://github.com/nao1215/gup/actions/workflows/multi_ver_unittest.yml/badge.svg)](https://github.com/nao1215/gup/actions/workflows/multi_ver_unittest.yml)
Expand Down Expand Up @@ -233,6 +233,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Akimon658"><img src="https://avatars.githubusercontent.com/u/81888693?v=4?s=100" width="100px;" alt="Akimo"/><br /><sub><b>Akimo</b></sub></a><br /><a href="https://github.com/nao1215/gup/commits?author=Akimon658" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/rkscv"><img src="https://avatars.githubusercontent.com/u/155284493?v=4?s=100" width="100px;" alt="rkscv"/><br /><sub><b>rkscv</b></sub></a><br /><a href="https://github.com/nao1215/gup/commits?author=rkscv" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
8 changes: 6 additions & 2 deletions cmd/bug_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ func newBugReportCmd() *cobra.Command {
Long: "bug-report opens the default browser to start a bug report which will include useful system information.",
Example: " gup bug-report",
Run: func(cmd *cobra.Command, args []string) {
OsExit(bugReport(cmd, args))
OsExit(bugReport(cmd, args, openBrowser))
},
}
}

func bugReport(cmd *cobra.Command, args []string) int { //nolint
// openBrowserFunc is a function that opens a browser to the specified URL.
type openBrowserFunc func(string) bool

// bugReport opens the default browser to start a bug report which will include useful system information.
func bugReport(cmd *cobra.Command, _ []string, openBrowser openBrowserFunc) int { //nolint
var buf bytes.Buffer

const (
Expand Down
20 changes: 20 additions & 0 deletions cmd/bug_report_linux_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//go:build linux

package cmd

import (
"runtime"
"testing"
)

func Test_openBrowser(t *testing.T) {
t.Parallel()
if runtime.GOOS != "linux" {
t.Skip("skipping test on non-linux system")
}

got := openBrowser("https://example.com")
if !got {
t.Error("openBrowser() = false; want true")
}
}
18 changes: 18 additions & 0 deletions cmd/bug_report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,21 @@ func TestBugReport(t *testing.T) {
}
})
}

func Test_bugReport(t *testing.T) {
t.Parallel()

cmd := newBugReportCmd()
cmd.Version = "v0.0.0"

wantReturnVal := 0
gotReturnVal := bugReport(cmd, nil, func(s string) bool {
if !strings.Contains(s, "v0.0.0") {
t.Errorf("Expected bug report to contain version number 'v0.0.0', but got: %s", s)
}
return true
})
if gotReturnVal != wantReturnVal {
t.Errorf("bugReport() = %d; want %d", gotReturnVal, wantReturnVal)
}
}

0 comments on commit 117823e

Please sign in to comment.