diff options
Diffstat (limited to 'commands/bug/testenv/testenv.go')
-rw-r--r-- | commands/bug/testenv/testenv.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/commands/bug/testenv/testenv.go b/commands/bug/testenv/testenv.go new file mode 100644 index 00000000..10f20950 --- /dev/null +++ b/commands/bug/testenv/testenv.go @@ -0,0 +1,63 @@ +package testenv + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/MichaelMure/git-bug/commands/execenv" + "github.com/MichaelMure/git-bug/entity" +) + +const ( + testUserName = "John Doe" + testUserEmail = "jdoe@example.com" +) + +func NewTestEnvAndUser(t *testing.T) (*execenv.Env, entity.Id) { + t.Helper() + + testEnv := execenv.NewTestEnv(t) + + i, err := testEnv.Backend.NewIdentity(testUserName, testUserEmail) + require.NoError(t, err) + + err = testEnv.Backend.SetUserIdentity(i) + require.NoError(t, err) + + return testEnv, i.Id() +} + +const ( + testBugTitle = "this is a bug title" + testBugMessage = "this is a bug message" +) + +func NewTestEnvAndBug(t *testing.T) (*execenv.Env, entity.Id) { + t.Helper() + + testEnv, _ := NewTestEnvAndUser(t) + + b, _, err := testEnv.Backend.NewBug(testBugTitle, testBugMessage) + require.NoError(t, err) + + return testEnv, b.Id() +} + +const ( + testCommentMessage = "this is a bug comment" +) + +func NewTestEnvAndBugWithComment(t *testing.T) (*execenv.Env, entity.Id, entity.CombinedId) { + t.Helper() + + env, bugID := NewTestEnvAndBug(t) + + b, err := env.Backend.ResolveBug(bugID) + require.NoError(t, err) + + commentId, _, err := b.AddComment(testCommentMessage) + require.NoError(t, err) + + return env, bugID, commentId +} |