diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2017-07-07 12:14:06 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2017-07-07 12:14:06 +0200 |
| commit | 23077b75410d6fab51762236f195d92bd559fc6a (patch) | |
| tree | 12ec00d832b3958d5194adeab4b73ff37aeeef4b /pkg/rtree/get_test.go | |
| parent | 79933615f7988cb731baa0768a45b39008f18b20 (diff) | |
| download | gofu-23077b75410d6fab51762236f195d92bd559fc6a.tar.gz | |
many more `rtree get` tests
Diffstat (limited to 'pkg/rtree/get_test.go')
| -rw-r--r-- | pkg/rtree/get_test.go | 136 |
1 files changed, 125 insertions, 11 deletions
diff --git a/pkg/rtree/get_test.go b/pkg/rtree/get_test.go index be7e092..8ab21f1 100644 --- a/pkg/rtree/get_test.go +++ b/pkg/rtree/get_test.go @@ -19,24 +19,138 @@ package rtree import ( + "fmt" "path/filepath" "testing" + + "github.com/majewsky/gofu/pkg/cli" ) -func TestGetRepoFromIndex(t *testing.T) { - idx := Index{ - Repos: []*Repo{ - { - CheckoutPath: "github.com/git/git", - Remotes: []Remote{ - {Name: "origin", URL: "gh:git/git"}, - }, +var testIndexWithTwoRepos = Index{ + Repos: []*Repo{ + { + CheckoutPath: "github.com/foo/bar", + Remotes: []Remote{ + {Name: "origin", URL: "https://github.com/foo/bar"}, + }, + }, + { + CheckoutPath: "github.com/git/git", + Remotes: []Remote{ + {Name: "origin", URL: "gh:git/git"}, }, }, - } + }, +} + +func TestGetExistingRepo(t *testing.T) { Test{ Args: []string{"get", "gh:git/git"}, - Index: idx, + Index: testIndexWithTwoRepos, + ExpectOutput: filepath.Join(RootPath, "/github.com/git/git") + "\n", + }.Run(t) +} + +func TestGetExistingRepoWithoutShortcut(t *testing.T) { + Test{ + Args: []string{"get", "https://github.com/git/git"}, + Index: testIndexWithTwoRepos, ExpectOutput: filepath.Join(RootPath, "/github.com/git/git") + "\n", - }.Run(t, "TestGetRepoFromIndex") + }.Run(t) +} + +func TestGetNewRepo(t *testing.T) { + target := filepath.Join(RootPath, "/github.com/another/repo") + + Test{ + Args: []string{"get", "gh:another/repo"}, + Index: testIndexWithTwoRepos, + ExpectOutput: target + "\n", + ExpectExecution: []RecordedCommand{ + {Cmd: cli.Command{ + Program: []string{"git", "clone", "gh:another/repo", target}, + }}, + }, + ExpectIndex: &Index{ + Repos: []*Repo{ + { + CheckoutPath: "github.com/another/repo", + Remotes: []Remote{ + {Name: "origin", URL: "gh:another/repo"}, + }, + }, + testIndexWithTwoRepos.Repos[0], + testIndexWithTwoRepos.Repos[1], + }, + }, + }.Run(t) +} + +func TestGetNewForkAsRemote(t *testing.T) { + target := filepath.Join(RootPath, "/github.com/git/git") + Test{ + Args: []string{"get", "https://example.com/git"}, + Index: testIndexWithTwoRepos, + Input: fmt.Sprintf("add as remote to %s\nmyfork\n", target), + ExpectOutput: target + "\n", + ExpectError: fmt.Sprintf( + "Found possible fork candidates. What to do? -> add as remote to %s\n"+ + "Existing remotes:\n\t(origin) gh:git/git\n"+ + "Enter remote name for https://example.com/git: myfork\n", + target, + ), + ExpectExecution: []RecordedCommand{ + {Cmd: cli.Command{ + Program: []string{"git", "remote", "add", "myfork", "https://example.com/git"}, + WorkDir: target, + }}, + {Cmd: cli.Command{ + Program: []string{"git", "remote", "update", "myfork"}, + WorkDir: target, + }}, + }, + ExpectIndex: &Index{ + Repos: []*Repo{ + testIndexWithTwoRepos.Repos[0], + { + CheckoutPath: "github.com/git/git", + Remotes: []Remote{ + {Name: "origin", URL: "gh:git/git"}, + {Name: "myfork", URL: "https://example.com/git"}, + }, + }, + }, + }, + }.Run(t) +} + +func TestGetNewForkAsSeparate(t *testing.T) { + target := filepath.Join(RootPath, "/example.com/git") + Test{ + Args: []string{"get", "https://example.com/git"}, + Index: testIndexWithTwoRepos, + Input: fmt.Sprintf("clone to %s\n", target), + ExpectOutput: target + "\n", + ExpectError: fmt.Sprintf( + "Found possible fork candidates. What to do? -> clone to %s\n", + target, + ), + ExpectExecution: []RecordedCommand{ + {Cmd: cli.Command{ + Program: []string{"git", "clone", "https://example.com/git", target}, + }}, + }, + ExpectIndex: &Index{ + Repos: []*Repo{ + { + CheckoutPath: "example.com/git", + Remotes: []Remote{ + {Name: "origin", URL: "https://example.com/git"}, + }, + }, + testIndexWithTwoRepos.Repos[0], + testIndexWithTwoRepos.Repos[1], + }, + }, + }.Run(t) } |
