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,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)