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,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)
|
||||
|
||||
Reference in New Issue
Block a user