mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
Tests: Refactor command tests
This commit is contained in:
@@ -3,22 +3,13 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUsersAddCommand(t *testing.T) {
|
||||
t.Run("AddUserThatAlreadyExists", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"add", "--name=Alice", "--email=jane@test.de", "--password=test1234", "--role=admin", "alice"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = UsersAddCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(UsersAddCommand, []string{"add", "--name=Alice", "--email=jane@test.de", "--password=test1234", "--role=admin", "alice"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
@@ -27,16 +18,8 @@ func TestUsersAddCommand(t *testing.T) {
|
||||
|
||||
})
|
||||
t.Run("AddDeletedUser", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"add", "--name=deleted", "--password=test1234", "deleted"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = UsersAddCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(UsersAddCommand, []string{"add", "--name=deleted", "--password=test1234", "deleted"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
@@ -45,16 +28,8 @@ func TestUsersAddCommand(t *testing.T) {
|
||||
|
||||
})
|
||||
t.Run("AddUsernameMissing", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"add", "--name=noname", "--password=test1234", "/##"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = UsersAddCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(UsersAddCommand, []string{"add", "--name=noname", "--password=test1234", "/##"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
|
||||
Reference in New Issue
Block a user