add_test.go

 1package commands_test
 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
15	testEnv.cmd.SetArgs([]string{
16		"add",
17		"--non-interactive",
18		"-t 'this is a bug title'",
19		"-m 'this is a bug message'",
20	})
21
22	testEnv.Execute(t)
23	require.Regexp(t, "^[0-9A-Fa-f]{7} created\n$", testEnv.out)
24	bugID := strings.Split(testEnv.out.String(), " ")[0]
25	testEnv.out.Reset()
26
27	return testEnv, userID, bugID
28}
29
30func TestAdd(t *testing.T) {
31	_, _, user := newTestEnvUserAndBug(t)
32	require.Regexp(t, "^[0-9A-Fa-f]{7}$", user)
33}