-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relax rules on code blocks, allowing three spaces (resolves #35)
Fix issue with packages that appear in both vendor/ and GOPATH (resolves #34) 'Open Terminal' support for linux/windows/etc (resolves #28)
- Loading branch information
KyleBanks
committed
Mar 24, 2017
1 parent
a2d39f0
commit ab50720
Showing
20 changed files
with
346 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package cmd | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/KyleBanks/goggles/conf" | ||
"github.com/KyleBanks/goggles/pkg/sys" | ||
) | ||
|
||
func Test_initConfig(t *testing.T) { | ||
tests := []struct { | ||
in string | ||
expect []string | ||
}{ | ||
{"", sys.Gopath()}, | ||
{"/foo/bar", []string{"/foo/bar"}}, | ||
{"/foo/bar:/foo/bar/baz", []string{"/foo/bar", "/foo/bar/baz"}}, | ||
} | ||
|
||
for idx, tt := range tests { | ||
defaultProvider = &mockProvider{ | ||
preferencesFn: func() *conf.Config { | ||
return &conf.Config{Gopath: tt.in} | ||
}, | ||
} | ||
|
||
initConfig() | ||
|
||
if out := sys.Gopath(); !reflect.DeepEqual(out, tt.expect) { | ||
t.Fatalf("[%v] Unexpected Gopath, expected=%v, got=%v", idx, tt.expect, out) | ||
} | ||
} | ||
} | ||
|
||
func Test_OpenLinks(t *testing.T) { | ||
tests := []struct { | ||
expect string | ||
fn func() | ||
}{ | ||
{aboutURL, OpenAbout}, | ||
{thanksURL, OpenThanks}, | ||
} | ||
|
||
for _, tt := range tests { | ||
var called bool | ||
defaultProvider = &mockProvider{ | ||
OpenBrowserFn: func(s string) { | ||
if s != tt.expect { | ||
t.Fatalf("Unexpected URL, expected=%v, got=%v", tt.expect, s) | ||
} | ||
called = true | ||
}, | ||
} | ||
|
||
tt.fn() | ||
if !called { | ||
t.Fatal("Expected OpenBrowser to be called") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/KyleBanks/goggles" | ||
"github.com/KyleBanks/goggles/conf" | ||
"github.com/KyleBanks/goggles/pkg/sys" | ||
) | ||
|
||
type mockProvider struct { | ||
ListFn func() ([]*goggles.Package, error) | ||
DetailsFn func(string) (*goggles.Package, error) | ||
|
||
OpenFileExplorerFn func(string) | ||
OpenTerminalFn func(string) | ||
OpenBrowserFn func(string) | ||
|
||
preferencesFn func() *conf.Config | ||
updatePreferencesFn func(*conf.Config) | ||
} | ||
|
||
func (m *mockProvider) List() ([]*goggles.Package, error) { return m.ListFn() } | ||
func (m *mockProvider) Details(n string) (*goggles.Package, error) { return m.DetailsFn(n) } | ||
func (m *mockProvider) OpenFileExplorer(n string) { m.OpenFileExplorerFn(n) } | ||
func (m *mockProvider) OpenTerminal(n string) { m.OpenTerminalFn(n) } | ||
func (m *mockProvider) OpenBrowser(n string) { m.OpenBrowserFn(n) } | ||
func (m *mockProvider) Preferences() *conf.Config { return m.preferencesFn() } | ||
func (m *mockProvider) UpdatePreferences(c *conf.Config) { m.updatePreferencesFn(c) } | ||
|
||
func TestProvider_Preferences(t *testing.T) { | ||
var p provider | ||
|
||
c := p.Preferences() | ||
if c == nil { | ||
t.Fatal("Unexpected nil Config") | ||
} | ||
} | ||
|
||
func TestProvider_UpdatePreferences(t *testing.T) { | ||
var p provider | ||
|
||
c := p.Preferences() | ||
sys.SetGopath("/not/a/real/gopath") | ||
p.UpdatePreferences(c) | ||
|
||
if sys.RawGopath() != c.Gopath { | ||
t.Fatalf("Unexpected RawGopath, expected=%v, got=%v", c.Gopath, sys.RawGopath()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.