add_test.go

 1package commands
 2
 3import (
 4	"strings"
 5	"testing"
 6
 7	"github.com/stretchr/testify/require"
 8)
 9
10func newTestEnvUserAndBug(t *testing.T) (*testEnv, string, string) {
11	t.Helper()
12
13	testEnv, userID := newTestEnvAndUser(t)
14	opts := addOptions{
15		title:          "this is a bug title",
16		message:        "this is a bug message",
17		messageFile:    "",
18		nonInteractive: true,
19	}
20
21	require.NoError(t, runAdd(testEnv.env, opts))
22	require.Regexp(t, "^[0-9A-Fa-f]{7} created\n$", testEnv.out)
23	bugID := strings.Split(testEnv.out.String(), " ")[0]
24	testEnv.out.Reset()
25
26	return testEnv, userID, bugID
27}
28
29func TestAdd(t *testing.T) {
30	_, _, user := newTestEnvUserAndBug(t)
31	require.Regexp(t, "^[0-9A-Fa-f]{7}$", user)
32}