diff options
Diffstat (limited to 'commands')
-rw-r--r-- | commands/user_create.go | 3 | ||||
-rw-r--r-- | commands/user_create_test.go | 37 |
2 files changed, 40 insertions, 0 deletions
diff --git a/commands/user_create.go b/commands/user_create.go index b5cb0528..14a13eac 100644 --- a/commands/user_create.go +++ b/commands/user_create.go @@ -22,6 +22,9 @@ func newUserCreateCommand() *cobra.Command { Short: "Create a new identity.", PreRunE: loadBackend(env), RunE: closeBackend(env, func(cmd *cobra.Command, args []string) error { + env.err = out{Writer: cmd.ErrOrStderr()} + env.out = out{Writer: cmd.OutOrStdout()} + return runUserCreate(env, options) }), } diff --git a/commands/user_create_test.go b/commands/user_create_test.go new file mode 100644 index 00000000..c2e2398f --- /dev/null +++ b/commands/user_create_test.go @@ -0,0 +1,37 @@ +package commands_test + +import ( + "path/filepath" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func newTestEnvAndUser(t *testing.T) (*testEnv, string) { + t.Helper() + + testEnv := newTestEnv(t) + + testEnv.cmd.SetArgs( + []string{ + "user", + "create", + "--non-interactive", + "-n John Doe", + "-e jdoe@example.com", + }) + + testEnv.Execute(t) + + return testEnv, strings.TrimSpace(testEnv.out.String()) +} + +func TestUserCreateCommand(t *testing.T) { + testEnv, userID := newTestEnvAndUser(t) + + t.Log("CWD:", testEnv.cwd) + + require.FileExists(t, filepath.Join(testEnv.cwd, ".git", "refs", "identities", userID)) + require.FileExists(t, filepath.Join(testEnv.cwd, ".git", "git-bug", "identity-cache")) +} |