aboutsummaryrefslogtreecommitdiffstats
path: root/commands/bug/select/select_test.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-12-27 19:40:40 +0100
committerMichael Muré <batolettre@gmail.com>2022-12-27 19:40:40 +0100
commite920987860dd9392fefc4b222aa4d2446b74f3d8 (patch)
tree7f67b211ed2a6342e4a3ca4e1011f3b91f0080bb /commands/bug/select/select_test.go
parent8cea6c7515e42cb8821a03c9bfebb0a8f63a01be (diff)
downloadgit-bug-e920987860dd9392fefc4b222aa4d2446b74f3d8.tar.gz
commands: generic "select" code, move bug completion in bugcmd
Diffstat (limited to 'commands/bug/select/select_test.go')
-rw-r--r--commands/bug/select/select_test.go79
1 files changed, 0 insertions, 79 deletions
diff --git a/commands/bug/select/select_test.go b/commands/bug/select/select_test.go
deleted file mode 100644
index 83ca6643..00000000
--- a/commands/bug/select/select_test.go
+++ /dev/null
@@ -1,79 +0,0 @@
-package _select
-
-import (
- "testing"
- "time"
-
- "github.com/stretchr/testify/require"
-
- "github.com/MichaelMure/git-bug/cache"
- "github.com/MichaelMure/git-bug/repository"
-)
-
-func TestSelect(t *testing.T) {
- repo := repository.CreateGoGitTestRepo(t, false)
-
- repoCache, err := cache.NewRepoCacheNoEvents(repo)
- require.NoError(t, err)
-
- _, _, err = ResolveBug(repoCache, []string{})
- require.Equal(t, ErrNoValidId, err)
-
- 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
-
- rene, err := repoCache.Identities().New("René Descartes", "rene@descartes.fr")
- require.NoError(t, err)
-
- for i := 0; i < 10; i++ {
- _, _, err := repoCache.Bugs().NewRaw(rene, time.Now().Unix(), "title", "message", nil, nil)
- require.NoError(t, err)
- }
-
- // and two more for testing
- b1, _, err := repoCache.Bugs().NewRaw(rene, time.Now().Unix(), "title", "message", nil, nil)
- require.NoError(t, err)
- b2, _, err := repoCache.Bugs().NewRaw(rene, time.Now().Unix(), "title", "message", nil, nil)
- require.NoError(t, err)
-
- err = Select(repoCache, b1.Id())
- require.NoError(t, err)
-
- // normal select without args
- b3, _, err := ResolveBug(repoCache, []string{})
- require.NoError(t, err)
- require.Equal(t, b1.Id(), b3.Id())
-
- // override selection with same id
- b4, _, err := ResolveBug(repoCache, []string{b1.Id().String()})
- require.NoError(t, err)
- require.Equal(t, b1.Id(), b4.Id())
-
- // override selection with a prefix
- b5, _, err := ResolveBug(repoCache, []string{b1.Id().Human()})
- require.NoError(t, err)
- require.Equal(t, b1.Id(), b5.Id())
-
- // args that shouldn't override
- 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(repoCache, []string{b2.Id().String()})
- require.NoError(t, err)
- require.Equal(t, b2.Id(), b7.Id())
-
- err = Clear(repoCache)
- require.NoError(t, err)
-
- // Resolve without a pattern should error again after clearing the selected bug
- _, _, err = ResolveBug(repoCache, []string{})
- require.Error(t, err)
-}