"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/cmd/browse/browse_test.go" between
gh-cli-1.12.1.tar.gz and gh-cli-1.13.1.tar.gz

About: GitHub CLI is GitHub’s official command line tool.

browse_test.go  (gh-cli-1.12.1):browse_test.go  (gh-cli-1.13.1)
package browse package browse
import ( import (
"fmt"
"net/http" "net/http"
"testing" "testing"
"github.com/cli/cli/internal/ghrepo" "github.com/cli/cli/internal/ghrepo"
"github.com/cli/cli/pkg/cmdutil" "github.com/cli/cli/pkg/cmdutil"
"github.com/cli/cli/pkg/httpmock" "github.com/cli/cli/pkg/httpmock"
"github.com/cli/cli/pkg/iostreams" "github.com/cli/cli/pkg/iostreams"
"github.com/google/shlex" "github.com/google/shlex"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
skipping to change at line 53 skipping to change at line 54
}, },
{ {
name: "wiki flag", name: "wiki flag",
cli: "--wiki", cli: "--wiki",
wants: BrowseOptions{ wants: BrowseOptions{
WikiFlag: true, WikiFlag: true,
}, },
wantsErr: false, wantsErr: false,
}, },
{ {
name: "no browser flag",
cli: "--no-browser",
wants: BrowseOptions{
NoBrowserFlag: true,
},
wantsErr: false,
},
{
name: "branch flag", name: "branch flag",
cli: "--branch main", cli: "--branch main",
wants: BrowseOptions{ wants: BrowseOptions{
Branch: "main", Branch: "main",
}, },
wantsErr: false, wantsErr: false,
}, },
{ {
name: "branch flag without a branch name", name: "branch flag without a branch name",
cli: "--branch", cli: "--branch",
skipping to change at line 121 skipping to change at line 130
assert.Error(t, err) assert.Error(t, err)
return return
} else { } else {
assert.NoError(t, err) assert.NoError(t, err)
} }
assert.Equal(t, tt.wants.Branch, opts.Branch) assert.Equal(t, tt.wants.Branch, opts.Branch)
assert.Equal(t, tt.wants.SelectorArg, opts.SelectorArg) assert.Equal(t, tt.wants.SelectorArg, opts.SelectorArg)
assert.Equal(t, tt.wants.ProjectsFlag, opts.ProjectsFlag) assert.Equal(t, tt.wants.ProjectsFlag, opts.ProjectsFlag)
assert.Equal(t, tt.wants.WikiFlag, opts.WikiFlag) assert.Equal(t, tt.wants.WikiFlag, opts.WikiFlag)
assert.Equal(t, tt.wants.NoBrowserFlag, opts.NoBrowserFla g)
assert.Equal(t, tt.wants.SettingsFlag, opts.SettingsFlag) assert.Equal(t, tt.wants.SettingsFlag, opts.SettingsFlag)
}) })
} }
} }
func Test_runBrowse(t *testing.T) { func Test_runBrowse(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
opts BrowseOptions opts BrowseOptions
baseRepo ghrepo.Interface baseRepo ghrepo.Interface
skipping to change at line 236 skipping to change at line 246
{ {
name: "opening branch file with line number", name: "opening branch file with line number",
opts: BrowseOptions{ opts: BrowseOptions{
Branch: "first-browse-pull", Branch: "first-browse-pull",
SelectorArg: "browse.go:32", SelectorArg: "browse.go:32",
}, },
baseRepo: ghrepo.New("github", "ThankYouGitHub"), baseRepo: ghrepo.New("github", "ThankYouGitHub"),
wantsErr: false, wantsErr: false,
expectedURL: "https://github.com/github/ThankYouGitHub/tr ee/first-browse-pull/browse.go#L32", expectedURL: "https://github.com/github/ThankYouGitHub/tr ee/first-browse-pull/browse.go#L32",
}, },
{
name: "no browser with branch file and line number",
opts: BrowseOptions{
Branch: "3-0-stable",
SelectorArg: "init.rb:6",
NoBrowserFlag: true,
},
baseRepo: ghrepo.New("mislav", "will_paginate"),
wantsErr: false,
expectedURL: "https://github.com/mislav/will_paginate/tre
e/3-0-stable/init.rb#L6",
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
io, _, stdout, stderr := iostreams.Test() io, _, stdout, stderr := iostreams.Test()
browser := cmdutil.TestBrowser{} browser := cmdutil.TestBrowser{}
reg := httpmock.Registry{} reg := httpmock.Registry{}
defer reg.Verify(t) defer reg.Verify(t)
if tt.defaultBranch != "" { if tt.defaultBranch != "" {
skipping to change at line 266 skipping to change at line 287
} }
opts.Browser = &browser opts.Browser = &browser
err := runBrowse(&opts) err := runBrowse(&opts)
if tt.wantsErr { if tt.wantsErr {
assert.Error(t, err) assert.Error(t, err)
} else { } else {
assert.NoError(t, err) assert.NoError(t, err)
} }
assert.Equal(t, "", stdout.String()) if opts.NoBrowserFlag {
assert.Equal(t, "", stderr.String()) assert.Equal(t, fmt.Sprintf("%s\n", tt.expectedUR
browser.Verify(t, tt.expectedURL) L), stdout.String())
assert.Equal(t, "", stderr.String())
browser.Verify(t, "")
} else {
assert.Equal(t, "", stdout.String())
assert.Equal(t, "", stderr.String())
browser.Verify(t, tt.expectedURL)
}
}) })
} }
} }
func Test_parseFileArg(t *testing.T) { func Test_parseFileArg(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
arg string arg string
errorExpected bool errorExpected bool
expectedFileArg string expectedFileArg string
 End of changes. 5 change blocks. 
3 lines changed or deleted 32 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)