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

fix(778): git bug rm broken #808

Merged
merged 20 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1659fed
test(778): capture stderr and stdout during tests
smoyer64 May 27, 2022
523a148
test(778): allow alternate CWD via context
smoyer64 May 27, 2022
5962ed8
test(778): verify root command returns main help text
smoyer64 May 27, 2022
50324b8
test(778): verify user create results in an identity and cache
smoyer64 May 27, 2022
508d0eb
test(778): clear output after user creation
smoyer64 May 28, 2022
ecfffe3
test(778): execute add user in testEnv and return userID
smoyer64 May 28, 2022
90208b5
test(778): execute rm bug in testEnv (hangs)
smoyer64 May 28, 2022
eda312f
fix(778): remove extra mutex lock when resolving bug prefix
smoyer64 Jun 1, 2022
cd1099a
fix(808): replace Windows line terminators
smoyer64 Jun 6, 2022
8fc93d8
Merge branch 'master' into fix/778-git-bug-rm-broken
smoyer64 Jun 6, 2022
5982e8f
chore(808): merge in LocalStorage namespace configuration
smoyer64 Jun 6, 2022
1a504e0
fix(808): simplify handling of Windows line terminations
smoyer64 Jun 6, 2022
99669d7
test(808): do not run golden file tests on Windows
smoyer64 Jun 6, 2022
54306a8
test(808): make build tag compatible with Go 1.16
smoyer64 Jun 6, 2022
848f725
fix(808): remove duplication stderr/stdout set-up
smoyer64 Jun 6, 2022
f0f5247
test(808): skip root help test that uses a golden file
smoyer64 Jun 7, 2022
6ec7d67
test(808): document getCWD() and clean-up arguments
smoyer64 Jun 7, 2022
941f5b3
chore(808): rearrange imports to git-bug convention
smoyer64 Jun 7, 2022
0a9aaa9
refactor(778): test only command implementations
smoyer64 Jun 15, 2022
d853a6f
test(778): simplify and guarantee backend cleanup
smoyer64 Jun 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions cache/repo_cache_bug.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,14 +499,10 @@ func (c *RepoCache) NewBugRaw(author *IdentityCache, unixTime int64, title strin

// RemoveBug removes a bug from the cache and repo given a bug id prefix
func (c *RepoCache) RemoveBug(prefix string) error {
c.muBug.RLock()
smoyer64 marked this conversation as resolved.
Show resolved Hide resolved

b, err := c.ResolveBugPrefix(prefix)
if err != nil {
c.muBug.RUnlock()
return err
}
c.muBug.RUnlock()

c.muBug.Lock()
err = bug.RemoveBug(c.repo, b.Id())
Expand Down
32 changes: 32 additions & 0 deletions commands/add_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package commands

import (
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func newTestEnvUserAndBug(t *testing.T) (*testEnv, string, string) {
t.Helper()

testEnv, userID := newTestEnvAndUser(t)
opts := addOptions{
title: "this is a bug title",
message: "this is a bug message",
messageFile: "",
nonInteractive: true,
}

require.NoError(t, runAdd(testEnv.env, opts))
require.Regexp(t, "^[0-9A-Fa-f]{7} created\n$", testEnv.out)
bugID := strings.Split(testEnv.out.String(), " ")[0]
testEnv.out.Reset()

return testEnv, userID, bugID
}

func TestAdd(t *testing.T) {
_, _, user := newTestEnvUserAndBug(t)
require.Regexp(t, "^[0-9A-Fa-f]{7}$", user)
}
48 changes: 48 additions & 0 deletions commands/env_testing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package commands

import (
"bytes"
"testing"

"github.com/stretchr/testify/require"

"github.com/MichaelMure/git-bug/cache"
"github.com/MichaelMure/git-bug/repository"
)

type testEnv struct {
env *Env
cwd string
out *bytes.Buffer
}

func newTestEnv(t *testing.T) *testEnv {
t.Helper()

cwd := t.TempDir()

repo, err := repository.InitGoGitRepo(cwd, gitBugNamespace)
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, repo.Close())
})

buf := new(bytes.Buffer)

backend, err := cache.NewRepoCache(repo)
require.NoError(t, err)
t.Cleanup(func() {
backend.Close()
})

return &testEnv{
env: &Env{
repo: repo,
backend: backend,
out: out{Writer: buf},
err: out{Writer: buf},
},
cwd: cwd,
out: buf,
}
}
17 changes: 17 additions & 0 deletions commands/rm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package commands

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestRm(t *testing.T) {
testEnv, _, bugID := newTestEnvUserAndBug(t)

exp := "bug " + bugID + " removed\n"

require.NoError(t, runRm(testEnv.env, []string{bugID}))
require.Equal(t, exp, testEnv.out.String())
testEnv.out.Reset()
}
36 changes: 36 additions & 0 deletions commands/user_create_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package commands

import (
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func newTestEnvAndUser(t *testing.T) (*testEnv, string) {
t.Helper()

testEnv := newTestEnv(t)

opts := createUserOptions{
name: "John Doe",
email: "jdoe@example.com",
avatarURL: "",
nonInteractive: true,
}

require.NoError(t, runUserCreate(testEnv.env, opts))

userID := strings.TrimSpace(testEnv.out.String())
testEnv.out.Reset()

return testEnv, userID
}

func TestUserCreateCommand(t *testing.T) {
testEnv, userID := newTestEnvAndUser(t)

require.FileExists(t, filepath.Join(testEnv.cwd, ".git", "refs", "identities", userID))
require.FileExists(t, filepath.Join(testEnv.cwd, ".git", "git-bug", "identity-cache"))
}