From d2483d83dd52365741f51eca106aa18c4e8d6420 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 16 Feb 2019 17:32:30 +0100 Subject: identity: I can compile again !! --- commands/select/select_test.go | 125 ++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 82 deletions(-) (limited to 'commands/select') diff --git a/commands/select/select_test.go b/commands/select/select_test.go index fe501d76..003dfc81 100644 --- a/commands/select/select_test.go +++ b/commands/select/select_test.go @@ -1,113 +1,74 @@ package _select import ( - "io/ioutil" - "log" "testing" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/repository" + "github.com/MichaelMure/git-bug/util/test" + "github.com/stretchr/testify/require" ) func TestSelect(t *testing.T) { - repo, err := cache.NewRepoCache(createRepo()) - checkErr(t, err) + repo := test.CreateRepo(false) + defer test.CleanupRepo(repo) - _, _, err = ResolveBug(repo, []string{}) - if err != ErrNoValidId { - t.Fatal("expected no valid id error, got", err) - } + repoCache, err := cache.NewRepoCache(repo) + require.NoError(t, err) - err = Select(repo, "invalid") - checkErr(t, err) + _, _, err = ResolveBug(repoCache, []string{}) + require.Equal(t, ErrNoValidId, err) - _, _, err = ResolveBug(repo, []string{}) - if err == nil { - t.Fatal("expected invalid bug error") - } + err = Select(repoCache, "invalid") + require.NoError(t, err) + + // Resolve without a pattern should fail when no bug is selected + _, _, err = ResolveBug(repoCache, []string{}) + require.Error(t, err) // generate a bunch of bugs for i := 0; i < 10; i++ { - _, err := repo.NewBug("title", "message") - checkErr(t, err) + _, err := repoCache.NewBug("title", "message") + require.NoError(t, err) } - // two more for testing - b1, err := repo.NewBug("title", "message") - checkErr(t, err) - b2, err := repo.NewBug("title", "message") - checkErr(t, err) + // and two more for testing + b1, err := repoCache.NewBug("title", "message") + require.NoError(t, err) + b2, err := repoCache.NewBug("title", "message") + require.NoError(t, err) - err = Select(repo, b1.Id()) - checkErr(t, err) + err = Select(repoCache, b1.Id()) + require.NoError(t, err) // normal select without args - b3, _, err := ResolveBug(repo, []string{}) - checkErr(t, err) - if b3.Id() != b1.Id() { - t.Fatal("incorrect bug returned") - } + b3, _, err := ResolveBug(repoCache, []string{}) + require.NoError(t, err) + require.Equal(t, b1.Id(), b3.Id()) // override selection with same id - b4, _, err := ResolveBug(repo, []string{b1.Id()}) - checkErr(t, err) - if b4.Id() != b1.Id() { - t.Fatal("incorrect bug returned") - } + b4, _, err := ResolveBug(repoCache, []string{b1.Id()}) + require.NoError(t, err) + require.Equal(t, b1.Id(), b4.Id()) // override selection with a prefix - b5, _, err := ResolveBug(repo, []string{b1.HumanId()}) - checkErr(t, err) - if b5.Id() != b1.Id() { - t.Fatal("incorrect bug returned") - } + b5, _, err := ResolveBug(repoCache, []string{b1.HumanId()}) + require.NoError(t, err) + require.Equal(t, b1.Id(), b5.Id()) // args that shouldn't override - b6, _, err := ResolveBug(repo, []string{"arg"}) - checkErr(t, err) - if b6.Id() != b1.Id() { - t.Fatal("incorrect bug returned") - } + b6, _, err := ResolveBug(repoCache, []string{"arg"}) + require.NoError(t, err) + require.Equal(t, b1.Id(), b6.Id()) // override with a different id - b7, _, err := ResolveBug(repo, []string{b2.Id()}) - checkErr(t, err) - if b7.Id() != b2.Id() { - t.Fatal("incorrect bug returned") - } - - err = Clear(repo) - checkErr(t, err) + b7, _, err := ResolveBug(repoCache, []string{b2.Id()}) + require.NoError(t, err) + require.Equal(t, b2.Id(), b7.Id()) - _, _, err = ResolveBug(repo, []string{}) - if err == nil { - t.Fatal("expected invalid bug error") - } -} + err = Clear(repoCache) + require.NoError(t, err) -func createRepo() *repository.GitRepo { - dir, err := ioutil.TempDir("", "") - if err != nil { - log.Fatal(err) - } - - repo, err := repository.InitGitRepo(dir) - if err != nil { - log.Fatal(err) - } - - if err := repo.StoreConfig("user.name", "testuser"); err != nil { - log.Fatal("failed to set user.name for test repository: ", err) - } - if err := repo.StoreConfig("user.email", "testuser@example.com"); err != nil { - log.Fatal("failed to set user.email for test repository: ", err) - } - - return repo -} - -func checkErr(t testing.TB, err error) { - if err != nil { - t.Fatal(err) - } + // Resolve without a pattern should error again after clearing the selected bug + _, _, err = ResolveBug(repoCache, []string{}) + require.Error(t, err) } -- cgit From da558b05ef79f4c80df10c6969a9ae5f4f764f96 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 16 Feb 2019 19:34:52 +0100 Subject: identity: all tests green o/ --- commands/select/select_test.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'commands/select') diff --git a/commands/select/select_test.go b/commands/select/select_test.go index 003dfc81..f26350f8 100644 --- a/commands/select/select_test.go +++ b/commands/select/select_test.go @@ -2,15 +2,16 @@ package _select import ( "testing" + "time" "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/identity" "github.com/MichaelMure/git-bug/util/test" "github.com/stretchr/testify/require" ) func TestSelect(t *testing.T) { repo := test.CreateRepo(false) - defer test.CleanupRepo(repo) repoCache, err := cache.NewRepoCache(repo) require.NoError(t, err) @@ -26,15 +27,18 @@ func TestSelect(t *testing.T) { require.Error(t, err) // generate a bunch of bugs + + rene := identity.NewBare("René Descartes", "rene@descartes.fr") + for i := 0; i < 10; i++ { - _, err := repoCache.NewBug("title", "message") + _, err := repoCache.NewBugRaw(rene, time.Now().Unix(), "title", "message", nil, nil) require.NoError(t, err) } // and two more for testing - b1, err := repoCache.NewBug("title", "message") + b1, err := repoCache.NewBugRaw(rene, time.Now().Unix(), "title", "message", nil, nil) require.NoError(t, err) - b2, err := repoCache.NewBug("title", "message") + b2, err := repoCache.NewBugRaw(rene, time.Now().Unix(), "title", "message", nil, nil) require.NoError(t, err) err = Select(repoCache, b1.Id()) @@ -71,4 +75,6 @@ func TestSelect(t *testing.T) { // Resolve without a pattern should error again after clearing the selected bug _, _, err = ResolveBug(repoCache, []string{}) require.Error(t, err) + + require.NoError(t, test.CleanupRepo(repo)) } -- cgit From 976af3a4e8382d03e9f2ccb57e2ed3b783294138 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 17 Feb 2019 17:59:54 +0100 Subject: identity: fix tests --- commands/select/select_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'commands/select') diff --git a/commands/select/select_test.go b/commands/select/select_test.go index f26350f8..29fdb3b8 100644 --- a/commands/select/select_test.go +++ b/commands/select/select_test.go @@ -5,7 +5,6 @@ import ( "time" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/identity" "github.com/MichaelMure/git-bug/util/test" "github.com/stretchr/testify/require" ) @@ -28,7 +27,8 @@ func TestSelect(t *testing.T) { // generate a bunch of bugs - rene := identity.NewBare("René Descartes", "rene@descartes.fr") + rene, err := repoCache.NewIdentity("René Descartes", "rene@descartes.fr") + require.NoError(t, err) for i := 0; i < 10; i++ { _, err := repoCache.NewBugRaw(rene, time.Now().Unix(), "title", "message", nil, nil) -- cgit