From 99b5c58d43137bd9f6503788a55484327b0c531f Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Mon, 12 Aug 2019 16:12:14 +0200 Subject: finish the refactoring for the dedicated identifier type --- commands/select/select.go | 9 +++++---- commands/select/select_test.go | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'commands/select') diff --git a/commands/select/select.go b/commands/select/select.go index 4ec3cb0e..fdc87154 100644 --- a/commands/select/select.go +++ b/commands/select/select.go @@ -11,6 +11,7 @@ import ( "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/entity" "github.com/MichaelMure/git-bug/repository" ) @@ -69,7 +70,7 @@ func ResolveBug(repo *cache.RepoCache, args []string) (*cache.BugCache, []string } // Select will select a bug for future use -func Select(repo *cache.RepoCache, id string) error { +func Select(repo *cache.RepoCache, id entity.Id) error { selectPath := selectFilePath(repo) f, err := os.OpenFile(selectPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) @@ -77,7 +78,7 @@ func Select(repo *cache.RepoCache, id string) error { return err } - _, err = f.WriteString(id) + _, err = f.WriteString(id.String()) if err != nil { return err } @@ -112,8 +113,8 @@ func selected(repo *cache.RepoCache) (*cache.BugCache, error) { return nil, fmt.Errorf("the select file should be < 100 bytes") } - id := string(buf) - if !bug.IDIsValid(id) { + id := entity.Id(buf) + if err := id.Validate(); err != nil { err = os.Remove(selectPath) if err != nil { return nil, errors.Wrap(err, "error while removing invalid select file") diff --git a/commands/select/select_test.go b/commands/select/select_test.go index 393ec88b..989d6b3c 100644 --- a/commands/select/select_test.go +++ b/commands/select/select_test.go @@ -52,12 +52,12 @@ func TestSelect(t *testing.T) { require.Equal(t, b1.Id(), b3.Id()) // override selection with same id - b4, _, err := ResolveBug(repoCache, []string{b1.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.HumanId()}) + b5, _, err := ResolveBug(repoCache, []string{b1.Id().Human()}) require.NoError(t, err) require.Equal(t, b1.Id(), b5.Id()) @@ -67,7 +67,7 @@ func TestSelect(t *testing.T) { require.Equal(t, b1.Id(), b6.Id()) // override with a different id - b7, _, err := ResolveBug(repoCache, []string{b2.Id()}) + b7, _, err := ResolveBug(repoCache, []string{b2.Id().String()}) require.NoError(t, err) require.Equal(t, b2.Id(), b7.Id()) -- cgit