Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove gomega #142

Merged
merged 15 commits into from
May 1, 2019
Merged
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
520 changes: 0 additions & 520 deletions CREDITS

Large diffs are not rendered by default.

115 changes: 74 additions & 41 deletions commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"path/filepath"
"testing"

. "github.com/onsi/gomega"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -81,8 +80,8 @@ type _updateArgs struct {
local string
}

func withFakeGitBackend(t *testing.T, block func(string, *_cloneArgs, *_updateArgs)) {
tmpRoot, err := ioutil.TempDir("", "ghq")
func withFakeGitBackend(t *testing.T, block func(*testing.T, string, *_cloneArgs, *_updateArgs)) {
tmpRoot, err := ioutil.TempDir("", "ghq-test")
if err != nil {
t.Fatalf("Could not create tempdir: %s", err)
}
Expand Down Expand Up @@ -115,8 +114,8 @@ func withFakeGitBackend(t *testing.T, block func(string, *_cloneArgs, *_updateAr
return tmpRoot
}()

defer func(orig []string) { _localRepositoryRoots = orig }(_localRepositoryRoots)
_localRepositoryRoots = []string{tmpRoot}
defer func() { _localRepositoryRoots = []string{} }()

var cloneArgs _cloneArgs
var updateArgs _updateArgs
Expand All @@ -142,107 +141,139 @@ func withFakeGitBackend(t *testing.T, block func(string, *_cloneArgs, *_updateAr
vcsDirsMap[".git"] = tmpBackend
defer func() { GitBackend = originalGitBackend; vcsDirsMap[".git"] = originalGitBackend }()

block(tmpRoot, &cloneArgs, &updateArgs)
block(t, tmpRoot, &cloneArgs, &updateArgs)
}

func TestCommandGet(t *testing.T) {
RegisterTestingT(t)
app := newApp()

testCases := []struct {
name string
f func(string, *_cloneArgs, *_updateArgs)
name string
scenario func(*testing.T, string, *_cloneArgs, *_updateArgs)
}{
{
name: "simple",
f: func(tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
scenario: func(t *testing.T, tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
localDir := filepath.Join(tmpRoot, "github.com", "motemen", "ghq-test-repo")

app.Run([]string{"", "get", "motemen/ghq-test-repo"})

Expect(cloneArgs.remote.String()).To(Equal("https://github.com/motemen/ghq-test-repo"))
Expect(filepath.ToSlash(cloneArgs.local)).To(Equal(filepath.ToSlash(localDir)))
Expect(cloneArgs.shallow).To(Equal(false))
expect := "https://github.com/motemen/ghq-test-repo"
if cloneArgs.remote.String() != expect {
t.Errorf("got: %s, expect: %s", cloneArgs.remote, expect)
}
if filepath.ToSlash(cloneArgs.local) != filepath.ToSlash(localDir) {
t.Errorf("got: %s, expect: %s", filepath.ToSlash(cloneArgs.local), filepath.ToSlash(localDir))
}
if cloneArgs.shallow {
t.Errorf("cloneArgs.shallow should be false")
}
},
},
{
name: "p option",
f: func(tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
name: "-p option",
scenario: func(t *testing.T, tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
localDir := filepath.Join(tmpRoot, "github.com", "motemen", "ghq-test-repo")

app.Run([]string{"", "get", "-p", "motemen/ghq-test-repo"})

Expect(cloneArgs.remote.String()).To(Equal("ssh://[email protected]/motemen/ghq-test-repo"))
Expect(filepath.ToSlash(cloneArgs.local)).To(Equal(filepath.ToSlash(localDir)))
Expect(cloneArgs.shallow).To(Equal(false))
expect := "ssh://[email protected]/motemen/ghq-test-repo"
if cloneArgs.remote.String() != expect {
t.Errorf("got: %s, expect: %s", cloneArgs.remote, expect)
}
if filepath.ToSlash(cloneArgs.local) != filepath.ToSlash(localDir) {
t.Errorf("got: %s, expect: %s", filepath.ToSlash(cloneArgs.local), filepath.ToSlash(localDir))
}
if cloneArgs.shallow {
t.Errorf("cloneArgs.shallow should be false")
}
},
},
{
name: "already cloned with -u",
f: func(tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
scenario: func(t *testing.T, tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
localDir := filepath.Join(tmpRoot, "github.com", "motemen", "ghq-test-repo")
// mark as "already cloned", the condition may change later
os.MkdirAll(filepath.Join(localDir, ".git"), 0755)

app.Run([]string{"", "get", "-u", "motemen/ghq-test-repo"})

Expect(updateArgs.local).To(Equal(localDir))
if updateArgs.local != localDir {
t.Errorf("got: %s, expect: %s", updateArgs.local, localDir)
}
},
},
{
name: "shallow",
f: func(tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
scenario: func(t *testing.T, tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
localDir := filepath.Join(tmpRoot, "github.com", "motemen", "ghq-test-repo")

app.Run([]string{"", "get", "-shallow", "motemen/ghq-test-repo"})

Expect(cloneArgs.remote.String()).To(Equal("https://github.com/motemen/ghq-test-repo"))
Expect(filepath.ToSlash(cloneArgs.local)).To(Equal(filepath.ToSlash(localDir)))
Expect(cloneArgs.shallow).To(Equal(true))
expect := "https://github.com/motemen/ghq-test-repo"
if cloneArgs.remote.String() != expect {
t.Errorf("got: %s, expect: %s", cloneArgs.remote, expect)
}
if filepath.ToSlash(cloneArgs.local) != filepath.ToSlash(localDir) {
t.Errorf("got: %s, expect: %s", filepath.ToSlash(cloneArgs.local), filepath.ToSlash(localDir))
}
if !cloneArgs.shallow {
t.Errorf("cloneArgs.shallow should be true")
}
},
},
{
name: "dot slach ./",
f: func(tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
scenario: func(t *testing.T, tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
localDir := filepath.Join(tmpRoot, "github.com", "motemen")
os.MkdirAll(localDir, 0755)
wd, _ := os.Getwd()
defer os.Chdir(wd)
os.Chdir(localDir)
defer os.Chdir(wd)

app.Run([]string{"", "get", "-u", "." + string(filepath.Separator) + "ghq-test-repo"})

Expect(cloneArgs.remote.String()).To(Equal("https://github.com/motemen/ghq-test-repo"))
Expect(cloneArgs.local).To(Equal(filepath.Join(localDir, "ghq-test-repo")))
expect := "https://github.com/motemen/ghq-test-repo"
if cloneArgs.remote.String() != expect {
t.Errorf("got: %s, expect: %s", cloneArgs.remote, expect)
}
expectDir := filepath.Join(localDir, "ghq-test-repo")
if cloneArgs.local != expectDir {
t.Errorf("got: %s, expect: %s", cloneArgs.local, expectDir)
}
},
},
{
name: "dot dot slash ../",
f: func(tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
scenario: func(t *testing.T, tmpRoot string, cloneArgs *_cloneArgs, updateArgs *_updateArgs) {
localDir := filepath.Join(tmpRoot, "github.com", "motemen", "ghq-test-repo")
os.MkdirAll(localDir, 0755)
wd, _ := os.Getwd()
defer os.Chdir(wd)
os.Chdir(localDir)
defer os.Chdir(wd)

app.Run([]string{"", "get", "-u", ".." + string(filepath.Separator) + "ghq-another-test-repo"})

Expect(cloneArgs.remote.String()).To(Equal("https://github.com/motemen/ghq-another-test-repo"))
Expect(cloneArgs.local).To(Equal(filepath.Join(tmpRoot, "github.com", "motemen", "ghq-another-test-repo")))
expect := "https://github.com/motemen/ghq-another-test-repo"
if cloneArgs.remote.String() != expect {
t.Errorf("got: %s, expect: %s", cloneArgs.remote, expect)
}
expectDir := filepath.Join(tmpRoot, "github.com", "motemen", "ghq-another-test-repo")
if cloneArgs.local != expectDir {
t.Errorf("got: %s, expect: %s", cloneArgs.local, expectDir)
}
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
withFakeGitBackend(t, tc.f)
withFakeGitBackend(t, tc.scenario)
})
}
}

func TestCommandList(t *testing.T) {
RegisterTestingT(t)

_, _, err := capture(func() {
app := cli.NewApp()
flagSet := flagSet("list", commandList.Flags)
Expand All @@ -251,12 +282,12 @@ func TestCommandList(t *testing.T) {
doList(c)
})

Expect(err).To(BeNil())
if err != nil {
t.Errorf("error should be nil, but: %s", err)
}
}

func TestCommandListUnique(t *testing.T) {
RegisterTestingT(t)

_, _, err := capture(func() {
app := cli.NewApp()
flagSet := flagSet("list", commandList.Flags)
Expand All @@ -266,12 +297,12 @@ func TestCommandListUnique(t *testing.T) {
doList(c)
})

Expect(err).To(BeNil())
if err != nil {
t.Errorf("error should be nil, but: %s", err)
}
}

func TestCommandListUnknown(t *testing.T) {
RegisterTestingT(t)

_, _, err := capture(func() {
app := cli.NewApp()
flagSet := flagSet("list", commandList.Flags)
Expand All @@ -281,5 +312,7 @@ func TestCommandListUnknown(t *testing.T) {
doList(c)
})

Expect(err).To(BeNil())
if err != nil {
t.Errorf("error should be nil, but: %s", err)
}
}
63 changes: 38 additions & 25 deletions git_test.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package main

import (
"testing"

. "github.com/onsi/gomega"
)
import "testing"

func TestGitConfigAll(t *testing.T) {
RegisterTestingT(t)

Expect(GitConfigAll("ghq.non.existent.key")).To(HaveLen(0))
dummyKey := "ghq.non.existent.key"
confs, err := GitConfigAll(dummyKey)
if err != nil {
t.Errorf("error should be nil but: %s", err)
}
if len(confs) > 0 {
t.Errorf("GitConfigAll(%q) = %v; want %v", dummyKey, confs, nil)
}
}

func TestGitConfigURL(t *testing.T) {
RegisterTestingT(t)

if GitHasFeatureConfigURLMatch() != nil {
t.Skip("Git does not have config --get-urlmatch feature")
}
Expand All @@ -30,19 +29,33 @@ vcs = hg
}
defer reset()

var (
value string
)

value, err = GitConfig("--get-urlmatch", "ghq.vcs", "https://ghe.example.com/foo/bar")
Expect(err).NotTo(HaveOccurred())
Expect(value).To(Equal("github"))

value, err = GitConfig("--get-urlmatch", "ghq.vcs", "https://ghe.example.com/hg/repo")
Expect(err).NotTo(HaveOccurred())
Expect(value).To(Equal("hg"))

value, err = GitConfig("--get-urlmatch", "ghq.vcs", "https://example.com")
Expect(err).NotTo(HaveOccurred())
Expect(value).To(Equal(""))
testCases := []struct {
name string
config []string
expect string
}{{
name: "github",
config: []string{"--get-urlmatch", "ghq.vcs", "https://ghe.example.com/foo/bar"},
expect: "github",
}, {
name: "hg",
config: []string{"--get-urlmatch", "ghq.vcs", "https://ghe.example.com/hg/repo"},
expect: "hg",
}, {
name: "empty",
config: []string{"--get-urlmatch", "ghq.vcs", "https://example.com"},
expect: "",
}}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
value, err := GitConfig(tc.config...)
if err != nil {
t.Errorf("error should be nil but: %s", err)
}
if value != tc.expect {
t.Errorf("got: %s, expect: %s", value, tc.expect)
}
})
}
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995 // indirect
github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e // indirect
github.com/motemen/go-colorine v0.0.0-20180816141035-45d19169413a
github.com/onsi/gomega v1.5.0
github.com/urfave/cli v1.20.0
golang.org/x/net v0.0.0-20190424112056-4829fb13d2c6
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09
golang.org/x/sync v0.0.0-20190423024810-112230192c58
)
30 changes: 4 additions & 26 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,20 @@ github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdn
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/daviddengcn/go-colortext v0.0.0-20180409174941-186a3d44e920 h1:d/cVoZOrJPJHKH1NdeUjyVAWKp4OpOT+Q+6T1sH7jeU=
github.com/daviddengcn/go-colortext v0.0.0-20180409174941-186a3d44e920/go.mod h1:dv4zxwHi5C/8AeI+4gX4dCWOIvNi7I6JCSX0HvlKPgE=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450 h1:7xqw01UYS+KCI25bMrPxwNYkSns2Db1ziQPpVq99FpE=
github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450/go.mod h1:Bk6SMAONeMXrxql8uvOKuAZSu8aM5RUGv+1C6IJaEho=
github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995 h1:f5gsjBiF9tRRVomCvrkGMMWI8W1f2OBFar2c5oakAP0=
github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995/go.mod h1:lJgMEyOkYFkPcDKwRXegd+iM6E7matEszMG5HhwytU8=
github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e h1:KhcknUwkWHKZPbFy2P7jH5LKJ3La+0ZeknkkmrSgqb0=
github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e/go.mod h1:0AA//k/eakGydO4jKRoRL2j92ZKSzTgj9tclaCrvXHk=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/motemen/go-colorine v0.0.0-20180816141035-45d19169413a h1:CONqI/36EjYzkAzrMD0UWuL/lRDr7UdoID4fDGke+Yc=
github.com/motemen/go-colorine v0.0.0-20180816141035-45d19169413a/go.mod h1:PU2urRC7j30rrabSyp1MGGhyoiWSninPD8ckjzBSgkU=
github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo=
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190424112056-4829fb13d2c6 h1:FP8hkuE6yUEaJnK7O2eTuejKWwW+Rhfj80dQ2JcKxCU=
golang.org/x/net v0.0.0-20190424112056-4829fb13d2c6/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09 h1:KaQtG+aDELoNmXYas3TVkGNYRuq8JQ1aa7LJt8EXVyo=
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
10 changes: 10 additions & 0 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"io/ioutil"
"net/url"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -42,5 +43,14 @@ func WithGitconfigFile(configContent string) (func(), error) {

return func() {
os.Setenv("GIT_CONFIG", prevGitConfigEnv)
os.RemoveAll(tmpdir)
}, nil
}

func mustParseURL(urlString string) *url.URL {
u, err := url.Parse(urlString)
if err != nil {
panic(err)
}
return u
}
Loading