From 1d4667c825bb5d291070bd4463c39a16f950f674 Mon Sep 17 00:00:00 2001 From: Steve Moyer Date: Thu, 16 Jun 2022 09:02:52 -0400 Subject: refactor(809): eliminate need to defer CleanupTestRepos() --- commands/env_testing.go | 2 ++ commands/select/select_test.go | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'commands') diff --git a/commands/env_testing.go b/commands/env_testing.go index 4de66a9d..b3c51c69 100644 --- a/commands/env_testing.go +++ b/commands/env_testing.go @@ -21,6 +21,8 @@ func newTestEnv(t *testing.T) *testEnv { cwd := t.TempDir() + // r := repository.CreateGoGitTestRepo(t, false) // TODO + repo, err := repository.InitGoGitRepo(cwd, gitBugNamespace) require.NoError(t, err) t.Cleanup(func() { diff --git a/commands/select/select_test.go b/commands/select/select_test.go index 488ab357..702700f4 100644 --- a/commands/select/select_test.go +++ b/commands/select/select_test.go @@ -11,8 +11,7 @@ import ( ) func TestSelect(t *testing.T) { - repo := repository.CreateGoGitTestRepo(false) - defer repository.CleanupTestRepos(repo) + repo := repository.CreateGoGitTestRepo(t, false) repoCache, err := cache.NewRepoCache(repo) require.NoError(t, err) -- cgit From f3d316d16cc9fadd90faaaf77becbb82f1e09367 Mon Sep 17 00:00:00 2001 From: Steve Moyer Date: Thu, 16 Jun 2022 19:45:51 -0400 Subject: test(809): remove remaining calls to InitGoRepo in tests Note that examples still need to shown how a developer would use the library. --- commands/env_testing.go | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'commands') diff --git a/commands/env_testing.go b/commands/env_testing.go index b3c51c69..48807725 100644 --- a/commands/env_testing.go +++ b/commands/env_testing.go @@ -19,15 +19,8 @@ type testEnv struct { func newTestEnv(t *testing.T) *testEnv { t.Helper() - cwd := t.TempDir() - - // r := repository.CreateGoGitTestRepo(t, false) // TODO - - repo, err := repository.InitGoGitRepo(cwd, gitBugNamespace) - require.NoError(t, err) - t.Cleanup(func() { - require.NoError(t, repo.Close()) - }) + repo := repository.CreateGoGitTestRepo(t, false) + cwd := repository.RepoDir(t, repo) buf := new(bytes.Buffer) -- cgit From 6fc6a0f0ab8ce8c7b6ec510d1d7557a6e7cd6835 Mon Sep 17 00:00:00 2001 From: Steve Moyer Date: Wed, 22 Jun 2022 10:38:09 -0400 Subject: test(809): remove reliance on repo's filesystem --- commands/add_test.go | 10 +++++----- commands/env_testing.go | 3 --- commands/rm_test.go | 2 +- commands/user_create_test.go | 16 +++++++++------- 4 files changed, 15 insertions(+), 16 deletions(-) (limited to 'commands') diff --git a/commands/add_test.go b/commands/add_test.go index 63eda06e..077995a6 100644 --- a/commands/add_test.go +++ b/commands/add_test.go @@ -7,10 +7,10 @@ import ( "github.com/stretchr/testify/require" ) -func newTestEnvUserAndBug(t *testing.T) (*testEnv, string, string) { +func newTestEnvAndBug(t *testing.T) (*testEnv, string) { t.Helper() - testEnv, userID := newTestEnvAndUser(t) + testEnv, _ := newTestEnvAndUser(t) opts := addOptions{ title: "this is a bug title", message: "this is a bug message", @@ -23,10 +23,10 @@ func newTestEnvUserAndBug(t *testing.T) (*testEnv, string, string) { bugID := strings.Split(testEnv.out.String(), " ")[0] testEnv.out.Reset() - return testEnv, userID, bugID + return testEnv, bugID } func TestAdd(t *testing.T) { - _, _, user := newTestEnvUserAndBug(t) - require.Regexp(t, "^[0-9A-Fa-f]{7}$", user) + _, bugID := newTestEnvAndBug(t) + require.Regexp(t, "^[0-9A-Fa-f]{7}$", bugID) } diff --git a/commands/env_testing.go b/commands/env_testing.go index 48807725..1493a190 100644 --- a/commands/env_testing.go +++ b/commands/env_testing.go @@ -12,7 +12,6 @@ import ( type testEnv struct { env *Env - cwd string out *bytes.Buffer } @@ -20,7 +19,6 @@ func newTestEnv(t *testing.T) *testEnv { t.Helper() repo := repository.CreateGoGitTestRepo(t, false) - cwd := repository.RepoDir(t, repo) buf := new(bytes.Buffer) @@ -37,7 +35,6 @@ func newTestEnv(t *testing.T) *testEnv { out: out{Writer: buf}, err: out{Writer: buf}, }, - cwd: cwd, out: buf, } } diff --git a/commands/rm_test.go b/commands/rm_test.go index 5d4e7cca..0156bbd4 100644 --- a/commands/rm_test.go +++ b/commands/rm_test.go @@ -7,7 +7,7 @@ import ( ) func TestRm(t *testing.T) { - testEnv, _, bugID := newTestEnvUserAndBug(t) + testEnv, bugID := newTestEnvAndBug(t) exp := "bug " + bugID + " removed\n" diff --git a/commands/user_create_test.go b/commands/user_create_test.go index 223e7ec3..08958344 100644 --- a/commands/user_create_test.go +++ b/commands/user_create_test.go @@ -1,21 +1,25 @@ package commands import ( - "path/filepath" "strings" "testing" "github.com/stretchr/testify/require" ) +const ( + testUserName = "John Doe" + testUserEmail = "jdoe@example.com" +) + func newTestEnvAndUser(t *testing.T) (*testEnv, string) { t.Helper() testEnv := newTestEnv(t) opts := createUserOptions{ - name: "John Doe", - email: "jdoe@example.com", + name: testUserName, + email: testUserEmail, avatarURL: "", nonInteractive: true, } @@ -29,8 +33,6 @@ func newTestEnvAndUser(t *testing.T) (*testEnv, string) { } 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")) + _, userID := newTestEnvAndUser(t) + require.Regexp(t, "[0-9a-f]{64}", userID) } -- cgit