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 TestAuthAddCommand(t *testing.T) {
|
||||
t.Run("Alice", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"add", "--scope=metrics", "--expires=5000", "--name=alice", "alice"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = AuthAddCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(AuthAddCommand, []string{"add", "--scope=metrics", "--expires=5000", "--name=alice", "alice"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
@@ -28,16 +19,8 @@ func TestAuthAddCommand(t *testing.T) {
|
||||
assert.Contains(t, output, "metrics")
|
||||
})
|
||||
t.Run("NoUser", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"add", "--scope=test", "--expires=5000", "--name=xyz"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = AuthAddCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(AuthAddCommand, []string{"add", "--scope=test", "--expires=5000", "--name=xyz"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
//t.Logf(output)
|
||||
@@ -47,16 +30,8 @@ func TestAuthAddCommand(t *testing.T) {
|
||||
assert.Contains(t, output, "test")
|
||||
})
|
||||
t.Run("UserNotFound", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"add", "--scope=test", "--expires=5000", "xxxxx"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = AuthAddCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(AuthAddCommand, []string{"add", "--scope=test", "--expires=5000", "xxxxx"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
//t.Logf(output)
|
||||
@@ -65,16 +40,8 @@ func TestAuthAddCommand(t *testing.T) {
|
||||
|
||||
})
|
||||
t.Run("NoClientName", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"add", "--scope=test", "--expires=5000", "alice"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = AuthAddCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(AuthAddCommand, []string{"add", "--scope=test", "--expires=5000", "alice"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
//t.Logf(output)
|
||||
@@ -82,16 +49,8 @@ func TestAuthAddCommand(t *testing.T) {
|
||||
assert.Empty(t, output)
|
||||
})
|
||||
t.Run("NoScope", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"add", "--name=test", "--expires=5000", "alice"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = AuthAddCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(AuthAddCommand, []string{"add", "--name=test", "--expires=5000", "alice"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
//t.Logf(output)
|
||||
|
||||
@@ -3,42 +3,24 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestAuthRemoveCommand(t *testing.T) {
|
||||
t.Run("NotConfirmed", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
args0 := []string{"show", "sessgh6123yt"}
|
||||
ctx0 := NewTestContext(args0)
|
||||
|
||||
output0 := capture.Output(func() {
|
||||
err = AuthShowCommand.Run(ctx0, args0...)
|
||||
})
|
||||
output0, err := RunWithTestContext(AuthShowCommand, []string{"show", "sessgh6123yt"})
|
||||
|
||||
// t.Logf(output0)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, output0)
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"rm", "sessgh6123yt"}
|
||||
ctx := NewTestContext(args)
|
||||
output, err := RunWithTestContext(AuthRemoveCommand, []string{"rm", "sessgh6123yt"})
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = AuthRemoveCommand.Run(ctx, args...)
|
||||
})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, output)
|
||||
|
||||
output1 := capture.Output(func() {
|
||||
err = AuthShowCommand.Run(ctx0, args0...)
|
||||
})
|
||||
output1, err := RunWithTestContext(AuthShowCommand, []string{"show", "sessgh6123yt"})
|
||||
|
||||
// t.Logf(output1)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -3,22 +3,13 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestAuthResetCommand(t *testing.T) {
|
||||
t.Run("NotConfirmed", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args0 := []string{"ls"}
|
||||
ctx0 := NewTestContext(args0)
|
||||
|
||||
// Run command with test context.
|
||||
output0 := capture.Output(func() {
|
||||
err = AuthListCommand.Run(ctx0, args0...)
|
||||
})
|
||||
output0, err := RunWithTestContext(AuthListCommand, []string{"ls"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
@@ -26,14 +17,8 @@ func TestAuthResetCommand(t *testing.T) {
|
||||
assert.Contains(t, output0, "alice")
|
||||
assert.Contains(t, output0, "visitor")
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"reset"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = AuthResetCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(AuthResetCommand, []string{"reset"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
//t.Logf(output)
|
||||
@@ -41,9 +26,7 @@ func TestAuthResetCommand(t *testing.T) {
|
||||
assert.Empty(t, output)
|
||||
|
||||
// Run command with test context.
|
||||
output1 := capture.Output(func() {
|
||||
err = AuthListCommand.Run(ctx0, args0...)
|
||||
})
|
||||
output1, err := RunWithTestContext(AuthListCommand, []string{"ls"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
|
||||
@@ -3,41 +3,24 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestAuthShowCommand(t *testing.T) {
|
||||
t.Run("All", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"show", "sess34q3hael"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = AuthShowCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(AuthShowCommand, []string{"show", "sess34q3hael"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
t.Logf(output)
|
||||
// t.Logf(output)
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, output, "alice")
|
||||
assert.Contains(t, output, "access_token")
|
||||
assert.Contains(t, output, "Client")
|
||||
})
|
||||
t.Run("NoResult", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"show", "sess34qxxxxx"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = AuthShowCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(AuthShowCommand, []string{"show", "sess34qxxxxx"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
|
||||
@@ -4,22 +4,12 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
)
|
||||
|
||||
func TestAuthCommands(t *testing.T) {
|
||||
t.Run("List", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"auth", "ls"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = AuthCommands.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(AuthCommands, []string{"auth", "ls"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
@@ -29,16 +19,8 @@ func TestAuthCommands(t *testing.T) {
|
||||
assert.Contains(t, output, "visitor")
|
||||
})
|
||||
t.Run("ListAlice", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"auth", "ls", "alice"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = AuthCommands.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(AuthCommands, []string{"auth", "ls", "alice"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
|
||||
@@ -3,21 +3,13 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestClientsAddCommand(t *testing.T) {
|
||||
t.Run("AddClient", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
args := []string{"add", "--name=Clara Client", "--scope=photos albums", "--expires=5000", "--tokens=2", "clara"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = ClientsAddCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(ClientsAddCommand, []string{"add", "--name=Clara Client", "--scope=photos albums", "--expires=5000", "--tokens=2", "clara"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
|
||||
@@ -3,52 +3,29 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestClientsModCommand(t *testing.T) {
|
||||
t.Run("ModNotExistingClient", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"mod", "--name=New", "--scope=test", "cs5cpu17n6gjxxxx"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = ClientsModCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(ClientsModCommand, []string{"mod", "--name=New", "--scope=test", "cs5cpu17n6gjxxxx"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
assert.Error(t, err)
|
||||
assert.Empty(t, output)
|
||||
})
|
||||
t.Run("DisableEnableAuth", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
args0 := []string{"show", "cs7pvt5h8rw9aaqj"}
|
||||
ctx0 := NewTestContext(args0)
|
||||
|
||||
// Run command with test context.
|
||||
output0 := capture.Output(func() {
|
||||
err = ClientsShowCommand.Run(ctx0, args0...)
|
||||
})
|
||||
output0, err := RunWithTestContext(ClientsShowCommand, []string{"show", "cs7pvt5h8rw9aaqj"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
t.Logf(output0)
|
||||
//t.Logf(output0)
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, output0, "AuthEnabled | true")
|
||||
assert.Contains(t, output0, "oauth2")
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"mod", "--disable", "cs7pvt5h8rw9aaqj"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = ClientsModCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(ClientsModCommand, []string{"mod", "--disable", "cs7pvt5h8rw9aaqj"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
//t.Logf(output)
|
||||
@@ -56,32 +33,22 @@ func TestClientsModCommand(t *testing.T) {
|
||||
assert.Empty(t, output)
|
||||
|
||||
// Run command with test context.
|
||||
output1 := capture.Output(func() {
|
||||
err = ClientsShowCommand.Run(ctx0, args0...)
|
||||
})
|
||||
output1, err := RunWithTestContext(ClientsShowCommand, []string{"show", "cs7pvt5h8rw9aaqj"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
//t.Logf(output1)
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, output1, "AuthEnabled | false")
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args1 := []string{"mod", "--enable", "cs7pvt5h8rw9aaqj"}
|
||||
ctx1 := NewTestContext(args1)
|
||||
|
||||
// Run command with test context.
|
||||
output2 := capture.Output(func() {
|
||||
err = ClientsModCommand.Run(ctx1, args1...)
|
||||
})
|
||||
output2, err := RunWithTestContext(ClientsModCommand, []string{"mod", "--enable", "cs7pvt5h8rw9aaqj"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, output2)
|
||||
|
||||
// Run command with test context.
|
||||
output3 := capture.Output(func() {
|
||||
err = ClientsShowCommand.Run(ctx0, args0...)
|
||||
})
|
||||
output3, err := RunWithTestContext(ClientsShowCommand, []string{"show", "cs7pvt5h8rw9aaqj"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
//t.Logf(output3)
|
||||
@@ -89,16 +56,8 @@ func TestClientsModCommand(t *testing.T) {
|
||||
assert.Contains(t, output3, "AuthEnabled | true")
|
||||
})
|
||||
t.Run("RegenerateSecret", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"mod", "--regenerate", "cs7pvt5h8rw9aaqj"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = ClientsModCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(ClientsModCommand, []string{"mod", "--regenerate", "cs7pvt5h8rw9aaqj"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
//t.Logf(output)
|
||||
|
||||
@@ -3,46 +3,29 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCientsRemoveCommand(t *testing.T) {
|
||||
t.Run("NoConfirmationProvided", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
args0 := []string{"show", "cs7pvt5h8rw9aaqj"}
|
||||
ctx0 := NewTestContext(args0)
|
||||
|
||||
output0 := capture.Output(func() {
|
||||
err = ClientsShowCommand.Run(ctx0, args0...)
|
||||
})
|
||||
// Run command with test context.
|
||||
output0, err := RunWithTestContext(ClientsShowCommand, []string{"show", "cs7pvt5h8rw9aaqj"})
|
||||
|
||||
//t.Logf(output0)
|
||||
assert.NoError(t, err)
|
||||
assert.NotContains(t, output0, "not found")
|
||||
assert.Contains(t, output0, "client")
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"rm", "cs7pvt5h8rw9aaqj"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = ClientsRemoveCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(ClientsRemoveCommand, []string{"rm", "cs7pvt5h8rw9aaqj"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
//t.Logf(output)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, output)
|
||||
|
||||
args2 := []string{"show", "cs7pvt5h8rw9aaqj"}
|
||||
ctx2 := NewTestContext(args2)
|
||||
|
||||
output2 := capture.Output(func() {
|
||||
err = ClientsShowCommand.Run(ctx2, args2...)
|
||||
})
|
||||
// Run command with test context.
|
||||
output2, err := RunWithTestContext(ClientsShowCommand, []string{"show", "cs7pvt5h8rw9aaqj"})
|
||||
|
||||
//t.Logf(output2)
|
||||
assert.NoError(t, err)
|
||||
@@ -50,54 +33,30 @@ func TestCientsRemoveCommand(t *testing.T) {
|
||||
assert.Contains(t, output2, "client")
|
||||
})
|
||||
t.Run("RemoveClient", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
args0 := []string{"show", "cs7pvt5h8rw9aaqj"}
|
||||
ctx0 := NewTestContext(args0)
|
||||
|
||||
output0 := capture.Output(func() {
|
||||
err = ClientsShowCommand.Run(ctx0, args0...)
|
||||
})
|
||||
// Run command with test context.
|
||||
output0, err := RunWithTestContext(ClientsShowCommand, []string{"show", "cs7pvt5h8rw9aaqj"})
|
||||
|
||||
//t.Logf(output0)
|
||||
assert.NoError(t, err)
|
||||
assert.NotContains(t, output0, "not found")
|
||||
assert.Contains(t, output0, "client")
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"rm", "--force", "cs7pvt5h8rw9aaqj"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = ClientsRemoveCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(ClientsRemoveCommand, []string{"rm", "--force", "cs7pvt5h8rw9aaqj"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, output)
|
||||
|
||||
args2 := []string{"show", "cs7pvt5h8rw9aaqj"}
|
||||
ctx2 := NewTestContext(args2)
|
||||
|
||||
output2 := capture.Output(func() {
|
||||
err = ClientsShowCommand.Run(ctx2, args2...)
|
||||
})
|
||||
// Run command with test context.
|
||||
output2, err := RunWithTestContext(ClientsShowCommand, []string{"show", "cs7pvt5h8rw9aaqj"})
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Empty(t, output2)
|
||||
})
|
||||
t.Run("NotFound", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"rm", "--force", "cs7pvt5h8rw9a000"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = ClientsRemoveCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(ClientsRemoveCommand, []string{"rm", "--force", "cs7pvt5h8rw9a000"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
assert.Error(t, err)
|
||||
|
||||
@@ -3,22 +3,13 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestClientsResetCommand(t *testing.T) {
|
||||
t.Run("NotConfirmed", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args0 := []string{"ls"}
|
||||
ctx0 := NewTestContext(args0)
|
||||
|
||||
// Run command with test context.
|
||||
output0 := capture.Output(func() {
|
||||
err = ClientsListCommand.Run(ctx0, args0...)
|
||||
})
|
||||
output0, err := RunWithTestContext(ClientsListCommand, []string{"ls"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
@@ -26,14 +17,8 @@ func TestClientsResetCommand(t *testing.T) {
|
||||
assert.Contains(t, output0, "alice")
|
||||
assert.Contains(t, output0, "metrics")
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"reset"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = ClientsResetCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(ClientsResetCommand, []string{"reset"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
//t.Logf(output)
|
||||
@@ -41,9 +26,7 @@ func TestClientsResetCommand(t *testing.T) {
|
||||
assert.Empty(t, output)
|
||||
|
||||
// Run command with test context.
|
||||
output1 := capture.Output(func() {
|
||||
err = ClientsListCommand.Run(ctx0, args0...)
|
||||
})
|
||||
output1, err := RunWithTestContext(ClientsListCommand, []string{"ls"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
|
||||
@@ -3,22 +3,13 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestClientsShowCommand(t *testing.T) {
|
||||
t.Run("All", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"show", "cs5gfen1bgxz7s9i"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = ClientsShowCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(ClientsShowCommand, []string{"show", "cs5gfen1bgxz7s9i"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
//t.Logf(output)
|
||||
@@ -28,16 +19,8 @@ func TestClientsShowCommand(t *testing.T) {
|
||||
assert.Contains(t, output, "confidential")
|
||||
})
|
||||
t.Run("NoResult", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"show", "cs5gfen1bgxzxxxx"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = ClientsShowCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(ClientsShowCommand, []string{"show", "cs5gfen1bgxzxxxx"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
|
||||
@@ -3,22 +3,13 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestEditionCommand(t *testing.T) {
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"edition"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = EditionCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(EditionCommand, []string{"edition"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
|
||||
@@ -3,22 +3,13 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestFindCommand(t *testing.T) {
|
||||
t.Run("All", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"find", "--csv"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = FindCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(FindCommand, []string{"find", "--csv"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
//t.Logf(output)
|
||||
|
||||
@@ -3,51 +3,29 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPasswdCommand(t *testing.T) {
|
||||
t.Run("UserNotFound", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
args := []string{"passwd", "--show", "mila"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = PasswdCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(PasswdCommand, []string{"passwd", "--show", "mila"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
assert.Error(t, err)
|
||||
assert.Empty(t, output)
|
||||
})
|
||||
t.Run("DeletedUser", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
args := []string{"passwd", "--show", "uqxqg7i1kperxvu8"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = PasswdCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(PasswdCommand, []string{"passwd", "--show", "uqxqg7i1kperxvu8"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
assert.Error(t, err)
|
||||
assert.Empty(t, output)
|
||||
})
|
||||
t.Run("DeletePassword", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
args := []string{"passwd", "--rm", "no_local_auth"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = PasswdCommand.Run(ctx)
|
||||
})
|
||||
output, err := RunWithTestContext(PasswdCommand, []string{"passwd", "--rm", "no_local_auth"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -3,18 +3,12 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestShowConfigOptionsCommand(t *testing.T) {
|
||||
var err error
|
||||
|
||||
args := []string{"config-options", "--md"}
|
||||
ctx := NewTestContext(args)
|
||||
output := capture.Stdout(func() {
|
||||
err = ShowConfigOptionsCommand.Run(ctx, args...)
|
||||
})
|
||||
// Run command with test context.
|
||||
output, err := RunWithTestContext(ShowConfigOptionsCommand, []string{"config-options", "--md"})
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, output, "PHOTOPRISM_IMPORT_PATH")
|
||||
|
||||
@@ -3,18 +3,12 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestShowConfigYamlCommand(t *testing.T) {
|
||||
var err error
|
||||
|
||||
args := []string{"config-yaml", "--md"}
|
||||
ctx := NewTestContext(args)
|
||||
output := capture.Stdout(func() {
|
||||
err = ShowConfigYamlCommand.Run(ctx, args...)
|
||||
})
|
||||
// Run command with test context.
|
||||
output, err := RunWithTestContext(ShowConfigYamlCommand, []string{"config-yaml", "--md"})
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -4,19 +4,11 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
)
|
||||
|
||||
func TestShowConfigCommand(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := config.CliTestContext()
|
||||
|
||||
output := capture.Output(func() {
|
||||
err = ShowConfigCommand.Run(ctx)
|
||||
})
|
||||
// Run command with test context.
|
||||
output, err := RunWithTestContext(ShowConfigCommand, []string{})
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -33,13 +25,8 @@ func TestShowConfigCommand(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestShowTagsCommand(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := config.CliTestContext()
|
||||
|
||||
output := capture.Output(func() {
|
||||
err = ShowMetadataCommand.Run(ctx)
|
||||
})
|
||||
// Run command with test context.
|
||||
output, err := RunWithTestContext(ShowMetadataCommand, []string{})
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -54,13 +41,8 @@ func TestShowTagsCommand(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestShowFiltersCommand(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := config.CliTestContext()
|
||||
|
||||
output := capture.Output(func() {
|
||||
err = ShowSearchFiltersCommand.Run(ctx)
|
||||
})
|
||||
// Run command with test context.
|
||||
output, err := RunWithTestContext(ShowSearchFiltersCommand, []string{})
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -75,13 +57,8 @@ func TestShowFiltersCommand(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestShowFormatsCommand(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := config.CliTestContext()
|
||||
|
||||
output := capture.Output(func() {
|
||||
err = ShowFileFormatsCommand.Run(ctx)
|
||||
})
|
||||
// Run command with test context.
|
||||
output, err := RunWithTestContext(ShowFileFormatsCommand, []string{})
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -3,19 +3,12 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestShowThumbSizesCommand(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := config.CliTestContext()
|
||||
|
||||
output := capture.Output(func() {
|
||||
err = ShowThumbSizesCommand.Run(ctx)
|
||||
})
|
||||
// Run command with test context.
|
||||
output, err := RunWithTestContext(ShowThumbSizesCommand, []string{})
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -3,19 +3,12 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestShowVideoSizesCommand(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := config.CliTestContext()
|
||||
|
||||
output := capture.Output(func() {
|
||||
err = ShowVideoSizesCommand.Run(ctx)
|
||||
})
|
||||
// Run command with test context.
|
||||
output, err := RunWithTestContext(ShowVideoSizesCommand, []string{})
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -3,22 +3,13 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUsersLegacyCommand(t *testing.T) {
|
||||
t.Run("All", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{""}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = UsersLegacyCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(UsersLegacyCommand, []string{""})
|
||||
|
||||
// Check command output for plausibility.
|
||||
//t.Logf(output)
|
||||
|
||||
@@ -3,22 +3,13 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUsersModCommand(t *testing.T) {
|
||||
t.Run("ModNotExistingUser", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"mod", "--name=New", "--email=new@test.de", "uqxqg7i1kperxxx0"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = UsersModCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(UsersModCommand, []string{"mod", "--name=New", "--email=new@test.de", "uqxqg7i1kperxxx0"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
@@ -26,16 +17,8 @@ func TestUsersModCommand(t *testing.T) {
|
||||
assert.Empty(t, output)
|
||||
})
|
||||
t.Run("ModDeletedUser", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"mod", "--name=New", "--email=new@test.de", "deleted"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = UsersModCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(UsersModCommand, []string{"mod", "--name=New", "--email=new@test.de", "deleted"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
|
||||
@@ -3,22 +3,13 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUsersRemoveCommand(t *testing.T) {
|
||||
t.Run("RemoveNotExistingUser", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"rm", "uqxqg7i1kperxxx0"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = UsersRemoveCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(UsersRemoveCommand, []string{"rm", "uqxqg7i1kperxxx0"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
@@ -26,16 +17,8 @@ func TestUsersRemoveCommand(t *testing.T) {
|
||||
assert.Empty(t, output)
|
||||
})
|
||||
t.Run("RemoveDeletedUser", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"rm", "deleted"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = UsersRemoveCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(UsersRemoveCommand, []string{"rm", "deleted"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
|
||||
@@ -3,22 +3,13 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUsersResetCommand(t *testing.T) {
|
||||
t.Run("NotConfirmed", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args0 := []string{"ls"}
|
||||
ctx0 := NewTestContext(args0)
|
||||
|
||||
// Run command with test context.
|
||||
output0 := capture.Output(func() {
|
||||
err = UsersListCommand.Run(ctx0, args0...)
|
||||
})
|
||||
output0, err := RunWithTestContext(UsersListCommand, []string{"ls"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
@@ -26,14 +17,8 @@ func TestUsersResetCommand(t *testing.T) {
|
||||
assert.Contains(t, output0, "alice")
|
||||
assert.Contains(t, output0, "bob")
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"reset"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = UsersResetCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(UsersResetCommand, []string{"reset"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
//t.Logf(output)
|
||||
@@ -41,9 +26,7 @@ func TestUsersResetCommand(t *testing.T) {
|
||||
assert.Empty(t, output)
|
||||
|
||||
// Run command with test context.
|
||||
output1 := capture.Output(func() {
|
||||
err = UsersListCommand.Run(ctx0, args0...)
|
||||
})
|
||||
output1, err := RunWithTestContext(UsersListCommand, []string{"ls"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
|
||||
@@ -3,22 +3,13 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUsersShowCommand(t *testing.T) {
|
||||
t.Run("Alice", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"show", "alice"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = UsersShowCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(UsersShowCommand, []string{"show", "alice"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
//t.Logf(output)
|
||||
@@ -28,16 +19,8 @@ func TestUsersShowCommand(t *testing.T) {
|
||||
assert.Contains(t, output, "alice@example.com")
|
||||
})
|
||||
t.Run("NoResult", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"show", "notexisting"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = UsersShowCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(UsersShowCommand, []string{"show", "notexisting"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
|
||||
@@ -3,35 +3,22 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUsersCommand(t *testing.T) {
|
||||
t.Run("AddModifyAndRemoveJohn", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Add John
|
||||
args := []string{"add", "--name=John", "--email=john@test.de", "--password=test1234", "--role=admin", "john"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = UsersAddCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(UsersAddCommand, []string{"add", "--name=John", "--email=john@test.de", "--password=test1234", "--role=admin", "john"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, output)
|
||||
|
||||
args2 := []string{"show", "john"}
|
||||
ctx2 := NewTestContext(args2)
|
||||
|
||||
// Run command with test context.
|
||||
output2 := capture.Output(func() {
|
||||
err = UsersShowCommand.Run(ctx2, args2...)
|
||||
})
|
||||
output2, err := RunWithTestContext(UsersShowCommand, []string{"show", "john"})
|
||||
|
||||
//t.Logf(output2)
|
||||
assert.NoError(t, err)
|
||||
@@ -40,24 +27,16 @@ func TestUsersCommand(t *testing.T) {
|
||||
assert.Contains(t, output2, "john@test.de")
|
||||
|
||||
//Modify John
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args3 := []string{"mod", "--name=Johnny", "--email=johnnny@test.de", "--password=test12345", "john"}
|
||||
ctx3 := NewTestContext(args3)
|
||||
|
||||
// Run command with test context.
|
||||
output3 := capture.Output(func() {
|
||||
err = UsersModCommand.Run(ctx3, args3...)
|
||||
})
|
||||
output3, err := RunWithTestContext(UsersModCommand, []string{"mod", "--name=Johnny", "--email=johnnny@test.de", "--password=test12345", "john"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output3)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, output3)
|
||||
|
||||
output4 := capture.Output(func() {
|
||||
err = UsersShowCommand.Run(ctx2, args2...)
|
||||
})
|
||||
// Run command with test context.
|
||||
output4, err := RunWithTestContext(UsersShowCommand, []string{"show", "john"})
|
||||
|
||||
//t.Logf(output4)
|
||||
assert.NoError(t, err)
|
||||
@@ -67,23 +46,16 @@ func TestUsersCommand(t *testing.T) {
|
||||
assert.Contains(t, output4, "| DeletedAt | <nil>")
|
||||
|
||||
//Remove John
|
||||
// Create test context with flags and arguments.
|
||||
args5 := []string{"rm", "--force", "john"}
|
||||
ctx5 := NewTestContext(args5)
|
||||
|
||||
// Run command with test context.
|
||||
output5 := capture.Output(func() {
|
||||
err = UsersRemoveCommand.Run(ctx5, args5...)
|
||||
})
|
||||
output5, err := RunWithTestContext(UsersRemoveCommand, []string{"rm", "--force", "john"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output5)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, output5)
|
||||
|
||||
output6 := capture.Output(func() {
|
||||
err = UsersShowCommand.Run(ctx2, args2...)
|
||||
})
|
||||
// Run command with test context.
|
||||
output6, err := RunWithTestContext(UsersShowCommand, []string{"show", "john"})
|
||||
|
||||
//t.Logf(output6)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -3,22 +3,13 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/pkg/capture"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestVersionCommand(t *testing.T) {
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
var err error
|
||||
|
||||
// Create test context with flags and arguments.
|
||||
args := []string{"version"}
|
||||
ctx := NewTestContext(args)
|
||||
|
||||
// Run command with test context.
|
||||
output := capture.Output(func() {
|
||||
err = VersionCommand.Run(ctx, args...)
|
||||
})
|
||||
output, err := RunWithTestContext(VersionCommand, []string{"version"})
|
||||
|
||||
// Check command output for plausibility.
|
||||
// t.Logf(output)
|
||||
|
||||
Reference in New Issue
Block a user