Tests: Refactor command tests

This commit is contained in:
graciousgrey
2024-12-09 15:11:39 +01:00
parent e39ac1729a
commit 3f26d79380
26 changed files with 89 additions and 552 deletions

View File

@@ -3,22 +3,13 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestAuthAddCommand(t *testing.T) { func TestAuthAddCommand(t *testing.T) {
t.Run("Alice", func(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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(AuthAddCommand, []string{"add", "--scope=metrics", "--expires=5000", "--name=alice", "alice"})
err = AuthAddCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)
@@ -28,16 +19,8 @@ func TestAuthAddCommand(t *testing.T) {
assert.Contains(t, output, "metrics") assert.Contains(t, output, "metrics")
}) })
t.Run("NoUser", func(t *testing.T) { 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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(AuthAddCommand, []string{"add", "--scope=test", "--expires=5000", "--name=xyz"})
err = AuthAddCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
//t.Logf(output) //t.Logf(output)
@@ -47,16 +30,8 @@ func TestAuthAddCommand(t *testing.T) {
assert.Contains(t, output, "test") assert.Contains(t, output, "test")
}) })
t.Run("UserNotFound", func(t *testing.T) { 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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(AuthAddCommand, []string{"add", "--scope=test", "--expires=5000", "xxxxx"})
err = AuthAddCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
//t.Logf(output) //t.Logf(output)
@@ -65,16 +40,8 @@ func TestAuthAddCommand(t *testing.T) {
}) })
t.Run("NoClientName", func(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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(AuthAddCommand, []string{"add", "--scope=test", "--expires=5000", "alice"})
err = AuthAddCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
//t.Logf(output) //t.Logf(output)
@@ -82,16 +49,8 @@ func TestAuthAddCommand(t *testing.T) {
assert.Empty(t, output) assert.Empty(t, output)
}) })
t.Run("NoScope", func(t *testing.T) { 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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(AuthAddCommand, []string{"add", "--name=test", "--expires=5000", "alice"})
err = AuthAddCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
//t.Logf(output) //t.Logf(output)

View File

@@ -3,42 +3,24 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestAuthRemoveCommand(t *testing.T) { func TestAuthRemoveCommand(t *testing.T) {
t.Run("NotConfirmed", func(t *testing.T) { t.Run("NotConfirmed", func(t *testing.T) {
var err error output0, err := RunWithTestContext(AuthShowCommand, []string{"show", "sessgh6123yt"})
args0 := []string{"show", "sessgh6123yt"}
ctx0 := NewTestContext(args0)
output0 := capture.Output(func() {
err = AuthShowCommand.Run(ctx0, args0...)
})
// t.Logf(output0) // t.Logf(output0)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotEmpty(t, output0) assert.NotEmpty(t, output0)
// Create test context with flags and arguments. output, err := RunWithTestContext(AuthRemoveCommand, []string{"rm", "sessgh6123yt"})
args := []string{"rm", "sessgh6123yt"}
ctx := NewTestContext(args)
// Run command with test context.
output := capture.Output(func() {
err = AuthRemoveCommand.Run(ctx, args...)
})
// Check command output for plausibility.
// t.Logf(output) // t.Logf(output)
assert.NoError(t, err) assert.NoError(t, err)
assert.Empty(t, output) assert.Empty(t, output)
output1 := capture.Output(func() { output1, err := RunWithTestContext(AuthShowCommand, []string{"show", "sessgh6123yt"})
err = AuthShowCommand.Run(ctx0, args0...)
})
// t.Logf(output1) // t.Logf(output1)
assert.NoError(t, err) assert.NoError(t, err)

View File

@@ -3,22 +3,13 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestAuthResetCommand(t *testing.T) { func TestAuthResetCommand(t *testing.T) {
t.Run("NotConfirmed", func(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. // Run command with test context.
output0 := capture.Output(func() { output0, err := RunWithTestContext(AuthListCommand, []string{"ls"})
err = AuthListCommand.Run(ctx0, args0...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)
@@ -26,14 +17,8 @@ func TestAuthResetCommand(t *testing.T) {
assert.Contains(t, output0, "alice") assert.Contains(t, output0, "alice")
assert.Contains(t, output0, "visitor") assert.Contains(t, output0, "visitor")
// Create test context with flags and arguments.
args := []string{"reset"}
ctx := NewTestContext(args)
// Run command with test context. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(AuthResetCommand, []string{"reset"})
err = AuthResetCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
//t.Logf(output) //t.Logf(output)
@@ -41,9 +26,7 @@ func TestAuthResetCommand(t *testing.T) {
assert.Empty(t, output) assert.Empty(t, output)
// Run command with test context. // Run command with test context.
output1 := capture.Output(func() { output1, err := RunWithTestContext(AuthListCommand, []string{"ls"})
err = AuthListCommand.Run(ctx0, args0...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)

View File

@@ -3,41 +3,24 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestAuthShowCommand(t *testing.T) { func TestAuthShowCommand(t *testing.T) {
t.Run("All", func(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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(AuthShowCommand, []string{"show", "sess34q3hael"})
err = AuthShowCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
t.Logf(output) // t.Logf(output)
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, output, "alice") assert.Contains(t, output, "alice")
assert.Contains(t, output, "access_token") assert.Contains(t, output, "access_token")
assert.Contains(t, output, "Client") assert.Contains(t, output, "Client")
}) })
t.Run("NoResult", func(t *testing.T) { 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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(AuthShowCommand, []string{"show", "sess34qxxxxx"})
err = AuthShowCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)

View File

@@ -4,22 +4,12 @@ import (
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/photoprism/photoprism/pkg/capture"
) )
func TestAuthCommands(t *testing.T) { func TestAuthCommands(t *testing.T) {
t.Run("List", func(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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(AuthCommands, []string{"auth", "ls"})
err = AuthCommands.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)
@@ -29,16 +19,8 @@ func TestAuthCommands(t *testing.T) {
assert.Contains(t, output, "visitor") assert.Contains(t, output, "visitor")
}) })
t.Run("ListAlice", func(t *testing.T) { 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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(AuthCommands, []string{"auth", "ls", "alice"})
err = AuthCommands.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)

View File

@@ -3,21 +3,13 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestClientsAddCommand(t *testing.T) { func TestClientsAddCommand(t *testing.T) {
t.Run("AddClient", func(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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(ClientsAddCommand, []string{"add", "--name=Clara Client", "--scope=photos albums", "--expires=5000", "--tokens=2", "clara"})
err = ClientsAddCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)

View File

@@ -3,52 +3,29 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestClientsModCommand(t *testing.T) { func TestClientsModCommand(t *testing.T) {
t.Run("ModNotExistingClient", func(t *testing.T) { t.Run("ModNotExistingClient", func(t *testing.T) {
var err error output, err := RunWithTestContext(ClientsModCommand, []string{"mod", "--name=New", "--scope=test", "cs5cpu17n6gjxxxx"})
// 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...)
})
// Check command output for plausibility. // Check command output for plausibility.
assert.Error(t, err) assert.Error(t, err)
assert.Empty(t, output) assert.Empty(t, output)
}) })
t.Run("DisableEnableAuth", func(t *testing.T) { t.Run("DisableEnableAuth", func(t *testing.T) {
var err error
args0 := []string{"show", "cs7pvt5h8rw9aaqj"}
ctx0 := NewTestContext(args0)
// Run command with test context. // Run command with test context.
output0 := capture.Output(func() { output0, err := RunWithTestContext(ClientsShowCommand, []string{"show", "cs7pvt5h8rw9aaqj"})
err = ClientsShowCommand.Run(ctx0, args0...)
})
// Check command output for plausibility. // Check command output for plausibility.
t.Logf(output0) //t.Logf(output0)
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, output0, "AuthEnabled | true") assert.Contains(t, output0, "AuthEnabled | true")
assert.Contains(t, output0, "oauth2") 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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(ClientsModCommand, []string{"mod", "--disable", "cs7pvt5h8rw9aaqj"})
err = ClientsModCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
//t.Logf(output) //t.Logf(output)
@@ -56,32 +33,22 @@ func TestClientsModCommand(t *testing.T) {
assert.Empty(t, output) assert.Empty(t, output)
// Run command with test context. // Run command with test context.
output1 := capture.Output(func() { output1, err := RunWithTestContext(ClientsShowCommand, []string{"show", "cs7pvt5h8rw9aaqj"})
err = ClientsShowCommand.Run(ctx0, args0...)
})
// Check command output for plausibility. // Check command output for plausibility.
//t.Logf(output1) //t.Logf(output1)
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, output1, "AuthEnabled | false") 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. // Run command with test context.
output2 := capture.Output(func() { output2, err := RunWithTestContext(ClientsModCommand, []string{"mod", "--enable", "cs7pvt5h8rw9aaqj"})
err = ClientsModCommand.Run(ctx1, args1...)
})
// Check command output for plausibility. // Check command output for plausibility.
assert.NoError(t, err) assert.NoError(t, err)
assert.Empty(t, output2) assert.Empty(t, output2)
// Run command with test context. // Run command with test context.
output3 := capture.Output(func() { output3, err := RunWithTestContext(ClientsShowCommand, []string{"show", "cs7pvt5h8rw9aaqj"})
err = ClientsShowCommand.Run(ctx0, args0...)
})
// Check command output for plausibility. // Check command output for plausibility.
//t.Logf(output3) //t.Logf(output3)
@@ -89,16 +56,8 @@ func TestClientsModCommand(t *testing.T) {
assert.Contains(t, output3, "AuthEnabled | true") assert.Contains(t, output3, "AuthEnabled | true")
}) })
t.Run("RegenerateSecret", func(t *testing.T) { 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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(ClientsModCommand, []string{"mod", "--regenerate", "cs7pvt5h8rw9aaqj"})
err = ClientsModCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
//t.Logf(output) //t.Logf(output)

View File

@@ -3,46 +3,29 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestCientsRemoveCommand(t *testing.T) { func TestCientsRemoveCommand(t *testing.T) {
t.Run("NoConfirmationProvided", func(t *testing.T) { t.Run("NoConfirmationProvided", func(t *testing.T) {
var err error // Run command with test context.
output0, err := RunWithTestContext(ClientsShowCommand, []string{"show", "cs7pvt5h8rw9aaqj"})
args0 := []string{"show", "cs7pvt5h8rw9aaqj"}
ctx0 := NewTestContext(args0)
output0 := capture.Output(func() {
err = ClientsShowCommand.Run(ctx0, args0...)
})
//t.Logf(output0) //t.Logf(output0)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotContains(t, output0, "not found") assert.NotContains(t, output0, "not found")
assert.Contains(t, output0, "client") assert.Contains(t, output0, "client")
// Create test context with flags and arguments.
args := []string{"rm", "cs7pvt5h8rw9aaqj"}
ctx := NewTestContext(args)
// Run command with test context. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(ClientsRemoveCommand, []string{"rm", "cs7pvt5h8rw9aaqj"})
err = ClientsRemoveCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
//t.Logf(output) //t.Logf(output)
assert.NoError(t, err) assert.NoError(t, err)
assert.Empty(t, output) assert.Empty(t, output)
args2 := []string{"show", "cs7pvt5h8rw9aaqj"} // Run command with test context.
ctx2 := NewTestContext(args2) output2, err := RunWithTestContext(ClientsShowCommand, []string{"show", "cs7pvt5h8rw9aaqj"})
output2 := capture.Output(func() {
err = ClientsShowCommand.Run(ctx2, args2...)
})
//t.Logf(output2) //t.Logf(output2)
assert.NoError(t, err) assert.NoError(t, err)
@@ -50,54 +33,30 @@ func TestCientsRemoveCommand(t *testing.T) {
assert.Contains(t, output2, "client") assert.Contains(t, output2, "client")
}) })
t.Run("RemoveClient", func(t *testing.T) { t.Run("RemoveClient", func(t *testing.T) {
var err error // Run command with test context.
output0, err := RunWithTestContext(ClientsShowCommand, []string{"show", "cs7pvt5h8rw9aaqj"})
args0 := []string{"show", "cs7pvt5h8rw9aaqj"}
ctx0 := NewTestContext(args0)
output0 := capture.Output(func() {
err = ClientsShowCommand.Run(ctx0, args0...)
})
//t.Logf(output0) //t.Logf(output0)
assert.NoError(t, err) assert.NoError(t, err)
assert.NotContains(t, output0, "not found") assert.NotContains(t, output0, "not found")
assert.Contains(t, output0, "client") 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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(ClientsRemoveCommand, []string{"rm", "--force", "cs7pvt5h8rw9aaqj"})
err = ClientsRemoveCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
assert.NoError(t, err) assert.NoError(t, err)
assert.Empty(t, output) assert.Empty(t, output)
args2 := []string{"show", "cs7pvt5h8rw9aaqj"} // Run command with test context.
ctx2 := NewTestContext(args2) output2, err := RunWithTestContext(ClientsShowCommand, []string{"show", "cs7pvt5h8rw9aaqj"})
output2 := capture.Output(func() {
err = ClientsShowCommand.Run(ctx2, args2...)
})
assert.Error(t, err) assert.Error(t, err)
assert.Empty(t, output2) assert.Empty(t, output2)
}) })
t.Run("NotFound", func(t *testing.T) { 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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(ClientsRemoveCommand, []string{"rm", "--force", "cs7pvt5h8rw9a000"})
err = ClientsRemoveCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
assert.Error(t, err) assert.Error(t, err)

View File

@@ -3,22 +3,13 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestClientsResetCommand(t *testing.T) { func TestClientsResetCommand(t *testing.T) {
t.Run("NotConfirmed", func(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. // Run command with test context.
output0 := capture.Output(func() { output0, err := RunWithTestContext(ClientsListCommand, []string{"ls"})
err = ClientsListCommand.Run(ctx0, args0...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)
@@ -26,14 +17,8 @@ func TestClientsResetCommand(t *testing.T) {
assert.Contains(t, output0, "alice") assert.Contains(t, output0, "alice")
assert.Contains(t, output0, "metrics") assert.Contains(t, output0, "metrics")
// Create test context with flags and arguments.
args := []string{"reset"}
ctx := NewTestContext(args)
// Run command with test context. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(ClientsResetCommand, []string{"reset"})
err = ClientsResetCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
//t.Logf(output) //t.Logf(output)
@@ -41,9 +26,7 @@ func TestClientsResetCommand(t *testing.T) {
assert.Empty(t, output) assert.Empty(t, output)
// Run command with test context. // Run command with test context.
output1 := capture.Output(func() { output1, err := RunWithTestContext(ClientsListCommand, []string{"ls"})
err = ClientsListCommand.Run(ctx0, args0...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)

View File

@@ -3,22 +3,13 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestClientsShowCommand(t *testing.T) { func TestClientsShowCommand(t *testing.T) {
t.Run("All", func(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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(ClientsShowCommand, []string{"show", "cs5gfen1bgxz7s9i"})
err = ClientsShowCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
//t.Logf(output) //t.Logf(output)
@@ -28,16 +19,8 @@ func TestClientsShowCommand(t *testing.T) {
assert.Contains(t, output, "confidential") assert.Contains(t, output, "confidential")
}) })
t.Run("NoResult", func(t *testing.T) { 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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(ClientsShowCommand, []string{"show", "cs5gfen1bgxzxxxx"})
err = ClientsShowCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)

View File

@@ -3,22 +3,13 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestEditionCommand(t *testing.T) { func TestEditionCommand(t *testing.T) {
t.Run("Success", func(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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(EditionCommand, []string{"edition"})
err = EditionCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)

View File

@@ -3,22 +3,13 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestFindCommand(t *testing.T) { func TestFindCommand(t *testing.T) {
t.Run("All", func(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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(FindCommand, []string{"find", "--csv"})
err = FindCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
//t.Logf(output) //t.Logf(output)

View File

@@ -3,51 +3,29 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestPasswdCommand(t *testing.T) { func TestPasswdCommand(t *testing.T) {
t.Run("UserNotFound", func(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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(PasswdCommand, []string{"passwd", "--show", "mila"})
err = PasswdCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
assert.Error(t, err) assert.Error(t, err)
assert.Empty(t, output) assert.Empty(t, output)
}) })
t.Run("DeletedUser", func(t *testing.T) { t.Run("DeletedUser", func(t *testing.T) {
var err error
args := []string{"passwd", "--show", "uqxqg7i1kperxvu8"}
ctx := NewTestContext(args)
// Run command with test context. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(PasswdCommand, []string{"passwd", "--show", "uqxqg7i1kperxvu8"})
err = PasswdCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
assert.Error(t, err) assert.Error(t, err)
assert.Empty(t, output) assert.Empty(t, output)
}) })
t.Run("DeletePassword", func(t *testing.T) { 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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(PasswdCommand, []string{"passwd", "--rm", "no_local_auth"})
err = PasswdCommand.Run(ctx)
})
// Check command output for plausibility. // Check command output for plausibility.
assert.NoError(t, err) assert.NoError(t, err)

View File

@@ -3,18 +3,12 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestShowConfigOptionsCommand(t *testing.T) { func TestShowConfigOptionsCommand(t *testing.T) {
var err error // Run command with test context.
output, err := RunWithTestContext(ShowConfigOptionsCommand, []string{"config-options", "--md"})
args := []string{"config-options", "--md"}
ctx := NewTestContext(args)
output := capture.Stdout(func() {
err = ShowConfigOptionsCommand.Run(ctx, args...)
})
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, output, "PHOTOPRISM_IMPORT_PATH") assert.Contains(t, output, "PHOTOPRISM_IMPORT_PATH")

View File

@@ -3,18 +3,12 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestShowConfigYamlCommand(t *testing.T) { func TestShowConfigYamlCommand(t *testing.T) {
var err error // Run command with test context.
output, err := RunWithTestContext(ShowConfigYamlCommand, []string{"config-yaml", "--md"})
args := []string{"config-yaml", "--md"}
ctx := NewTestContext(args)
output := capture.Stdout(func() {
err = ShowConfigYamlCommand.Run(ctx, args...)
})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@@ -4,19 +4,11 @@ import (
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/pkg/capture"
) )
func TestShowConfigCommand(t *testing.T) { func TestShowConfigCommand(t *testing.T) {
var err error // Run command with test context.
output, err := RunWithTestContext(ShowConfigCommand, []string{})
ctx := config.CliTestContext()
output := capture.Output(func() {
err = ShowConfigCommand.Run(ctx)
})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -33,13 +25,8 @@ func TestShowConfigCommand(t *testing.T) {
} }
func TestShowTagsCommand(t *testing.T) { func TestShowTagsCommand(t *testing.T) {
var err error // Run command with test context.
output, err := RunWithTestContext(ShowMetadataCommand, []string{})
ctx := config.CliTestContext()
output := capture.Output(func() {
err = ShowMetadataCommand.Run(ctx)
})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -54,13 +41,8 @@ func TestShowTagsCommand(t *testing.T) {
} }
func TestShowFiltersCommand(t *testing.T) { func TestShowFiltersCommand(t *testing.T) {
var err error // Run command with test context.
output, err := RunWithTestContext(ShowSearchFiltersCommand, []string{})
ctx := config.CliTestContext()
output := capture.Output(func() {
err = ShowSearchFiltersCommand.Run(ctx)
})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@@ -75,13 +57,8 @@ func TestShowFiltersCommand(t *testing.T) {
} }
func TestShowFormatsCommand(t *testing.T) { func TestShowFormatsCommand(t *testing.T) {
var err error // Run command with test context.
output, err := RunWithTestContext(ShowFileFormatsCommand, []string{})
ctx := config.CliTestContext()
output := capture.Output(func() {
err = ShowFileFormatsCommand.Run(ctx)
})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@@ -3,19 +3,12 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestShowThumbSizesCommand(t *testing.T) { func TestShowThumbSizesCommand(t *testing.T) {
var err error // Run command with test context.
output, err := RunWithTestContext(ShowThumbSizesCommand, []string{})
ctx := config.CliTestContext()
output := capture.Output(func() {
err = ShowThumbSizesCommand.Run(ctx)
})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@@ -3,19 +3,12 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestShowVideoSizesCommand(t *testing.T) { func TestShowVideoSizesCommand(t *testing.T) {
var err error // Run command with test context.
output, err := RunWithTestContext(ShowVideoSizesCommand, []string{})
ctx := config.CliTestContext()
output := capture.Output(func() {
err = ShowVideoSizesCommand.Run(ctx)
})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@@ -3,22 +3,13 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestUsersAddCommand(t *testing.T) { func TestUsersAddCommand(t *testing.T) {
t.Run("AddUserThatAlreadyExists", func(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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(UsersAddCommand, []string{"add", "--name=Alice", "--email=jane@test.de", "--password=test1234", "--role=admin", "alice"})
err = UsersAddCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)
@@ -27,16 +18,8 @@ func TestUsersAddCommand(t *testing.T) {
}) })
t.Run("AddDeletedUser", func(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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(UsersAddCommand, []string{"add", "--name=deleted", "--password=test1234", "deleted"})
err = UsersAddCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)
@@ -45,16 +28,8 @@ func TestUsersAddCommand(t *testing.T) {
}) })
t.Run("AddUsernameMissing", func(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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(UsersAddCommand, []string{"add", "--name=noname", "--password=test1234", "/##"})
err = UsersAddCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)

View File

@@ -3,22 +3,13 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestUsersLegacyCommand(t *testing.T) { func TestUsersLegacyCommand(t *testing.T) {
t.Run("All", func(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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(UsersLegacyCommand, []string{""})
err = UsersLegacyCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
//t.Logf(output) //t.Logf(output)

View File

@@ -3,22 +3,13 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestUsersModCommand(t *testing.T) { func TestUsersModCommand(t *testing.T) {
t.Run("ModNotExistingUser", func(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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(UsersModCommand, []string{"mod", "--name=New", "--email=new@test.de", "uqxqg7i1kperxxx0"})
err = UsersModCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)
@@ -26,16 +17,8 @@ func TestUsersModCommand(t *testing.T) {
assert.Empty(t, output) assert.Empty(t, output)
}) })
t.Run("ModDeletedUser", func(t *testing.T) { 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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(UsersModCommand, []string{"mod", "--name=New", "--email=new@test.de", "deleted"})
err = UsersModCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)

View File

@@ -3,22 +3,13 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestUsersRemoveCommand(t *testing.T) { func TestUsersRemoveCommand(t *testing.T) {
t.Run("RemoveNotExistingUser", func(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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(UsersRemoveCommand, []string{"rm", "uqxqg7i1kperxxx0"})
err = UsersRemoveCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)
@@ -26,16 +17,8 @@ func TestUsersRemoveCommand(t *testing.T) {
assert.Empty(t, output) assert.Empty(t, output)
}) })
t.Run("RemoveDeletedUser", func(t *testing.T) { 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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(UsersRemoveCommand, []string{"rm", "deleted"})
err = UsersRemoveCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)

View File

@@ -3,22 +3,13 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestUsersResetCommand(t *testing.T) { func TestUsersResetCommand(t *testing.T) {
t.Run("NotConfirmed", func(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. // Run command with test context.
output0 := capture.Output(func() { output0, err := RunWithTestContext(UsersListCommand, []string{"ls"})
err = UsersListCommand.Run(ctx0, args0...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)
@@ -26,14 +17,8 @@ func TestUsersResetCommand(t *testing.T) {
assert.Contains(t, output0, "alice") assert.Contains(t, output0, "alice")
assert.Contains(t, output0, "bob") assert.Contains(t, output0, "bob")
// Create test context with flags and arguments.
args := []string{"reset"}
ctx := NewTestContext(args)
// Run command with test context. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(UsersResetCommand, []string{"reset"})
err = UsersResetCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
//t.Logf(output) //t.Logf(output)
@@ -41,9 +26,7 @@ func TestUsersResetCommand(t *testing.T) {
assert.Empty(t, output) assert.Empty(t, output)
// Run command with test context. // Run command with test context.
output1 := capture.Output(func() { output1, err := RunWithTestContext(UsersListCommand, []string{"ls"})
err = UsersListCommand.Run(ctx0, args0...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)

View File

@@ -3,22 +3,13 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestUsersShowCommand(t *testing.T) { func TestUsersShowCommand(t *testing.T) {
t.Run("Alice", func(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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(UsersShowCommand, []string{"show", "alice"})
err = UsersShowCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
//t.Logf(output) //t.Logf(output)
@@ -28,16 +19,8 @@ func TestUsersShowCommand(t *testing.T) {
assert.Contains(t, output, "alice@example.com") assert.Contains(t, output, "alice@example.com")
}) })
t.Run("NoResult", func(t *testing.T) { 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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(UsersShowCommand, []string{"show", "notexisting"})
err = UsersShowCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)

View File

@@ -3,35 +3,22 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestUsersCommand(t *testing.T) { func TestUsersCommand(t *testing.T) {
t.Run("AddModifyAndRemoveJohn", func(t *testing.T) { t.Run("AddModifyAndRemoveJohn", func(t *testing.T) {
var err error
// Add John // Add John
args := []string{"add", "--name=John", "--email=john@test.de", "--password=test1234", "--role=admin", "john"}
ctx := NewTestContext(args)
// Run command with test context. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(UsersAddCommand, []string{"add", "--name=John", "--email=john@test.de", "--password=test1234", "--role=admin", "john"})
err = UsersAddCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)
assert.NoError(t, err) assert.NoError(t, err)
assert.Empty(t, output) assert.Empty(t, output)
args2 := []string{"show", "john"}
ctx2 := NewTestContext(args2)
// Run command with test context. // Run command with test context.
output2 := capture.Output(func() { output2, err := RunWithTestContext(UsersShowCommand, []string{"show", "john"})
err = UsersShowCommand.Run(ctx2, args2...)
})
//t.Logf(output2) //t.Logf(output2)
assert.NoError(t, err) assert.NoError(t, err)
@@ -40,24 +27,16 @@ func TestUsersCommand(t *testing.T) {
assert.Contains(t, output2, "john@test.de") assert.Contains(t, output2, "john@test.de")
//Modify John //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. // Run command with test context.
output3 := capture.Output(func() { output3, err := RunWithTestContext(UsersModCommand, []string{"mod", "--name=Johnny", "--email=johnnny@test.de", "--password=test12345", "john"})
err = UsersModCommand.Run(ctx3, args3...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output3) // t.Logf(output3)
assert.NoError(t, err) assert.NoError(t, err)
assert.Empty(t, output3) assert.Empty(t, output3)
output4 := capture.Output(func() { // Run command with test context.
err = UsersShowCommand.Run(ctx2, args2...) output4, err := RunWithTestContext(UsersShowCommand, []string{"show", "john"})
})
//t.Logf(output4) //t.Logf(output4)
assert.NoError(t, err) assert.NoError(t, err)
@@ -67,23 +46,16 @@ func TestUsersCommand(t *testing.T) {
assert.Contains(t, output4, "| DeletedAt | <nil>") assert.Contains(t, output4, "| DeletedAt | <nil>")
//Remove John //Remove John
// Create test context with flags and arguments.
args5 := []string{"rm", "--force", "john"}
ctx5 := NewTestContext(args5)
// Run command with test context. // Run command with test context.
output5 := capture.Output(func() { output5, err := RunWithTestContext(UsersRemoveCommand, []string{"rm", "--force", "john"})
err = UsersRemoveCommand.Run(ctx5, args5...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output5) // t.Logf(output5)
assert.NoError(t, err) assert.NoError(t, err)
assert.Empty(t, output5) assert.Empty(t, output5)
output6 := capture.Output(func() { // Run command with test context.
err = UsersShowCommand.Run(ctx2, args2...) output6, err := RunWithTestContext(UsersShowCommand, []string{"show", "john"})
})
//t.Logf(output6) //t.Logf(output6)
assert.NoError(t, err) assert.NoError(t, err)

View File

@@ -3,22 +3,13 @@ package commands
import ( import (
"testing" "testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestVersionCommand(t *testing.T) { func TestVersionCommand(t *testing.T) {
t.Run("Success", func(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. // Run command with test context.
output := capture.Output(func() { output, err := RunWithTestContext(VersionCommand, []string{"version"})
err = VersionCommand.Run(ctx, args...)
})
// Check command output for plausibility. // Check command output for plausibility.
// t.Logf(output) // t.Logf(output)