From f5bcef4086c32d0f1427bc8a5adb440c26c1c16b Mon Sep 17 00:00:00 2001 From: graciousgrey Date: Mon, 29 Jan 2024 16:47:51 +0100 Subject: [PATCH] Tests: Add unit tests --- internal/commands/clients_mod_test.go | 118 ++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 internal/commands/clients_mod_test.go diff --git a/internal/commands/clients_mod_test.go b/internal/commands/clients_mod_test.go new file mode 100644 index 000000000..cd029aa63 --- /dev/null +++ b/internal/commands/clients_mod_test.go @@ -0,0 +1,118 @@ +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. + ctx := NewTestContext([]string{"mod", "--name=New", "--scope=test", "cs5cpu17n6gjxxxx"}) + + // Run command with test context. + output := capture.Output(func() { + err = ClientsModCommand.Run(ctx) + }) + + // Check command output for plausibility. + assert.Error(t, err) + assert.Empty(t, output) + }) + t.Run("ModDeletedClient", func(t *testing.T) { + var err error + + // Create test context with flags and arguments. + ctx := NewTestContext([]string{"mod", "--name=New", "--scope=test", "cs5cpu17n6gj2gf7"}) + + // Run command with test context. + output := capture.Output(func() { + err = ClientsModCommand.Run(ctx) + }) + + // Check command output for plausibility. + assert.Error(t, err) + assert.Empty(t, output) + }) + t.Run("DisableEnableAuth", func(t *testing.T) { + var err error + + ctx0 := NewTestContext([]string{"show", "cs7pvt5h8rw9aaqj"}) + + // Run command with test context. + output0 := capture.Output(func() { + err = ClientsShowCommand.Run(ctx0) + }) + + // Check command output for plausibility. + 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. + ctx := NewTestContext([]string{"mod", "--disable", "cs7pvt5h8rw9aaqj"}) + + // Run command with test context. + output := capture.Output(func() { + err = ClientsModCommand.Run(ctx) + }) + + // Check command output for plausibility. + //t.Logf(output) + assert.NoError(t, err) + assert.Empty(t, output) + + // Run command with test context. + output1 := capture.Output(func() { + err = ClientsShowCommand.Run(ctx0) + }) + + // 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. + ctx1 := NewTestContext([]string{"mod", "--enable", "cs7pvt5h8rw9aaqj"}) + + // Run command with test context. + output2 := capture.Output(func() { + err = ClientsModCommand.Run(ctx1) + }) + + // 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) + }) + + // Check command output for plausibility. + //t.Logf(output3) + assert.NoError(t, err) + assert.Contains(t, output3, "AuthEnabled | true") + }) + t.Run("RegenerateSecret", func(t *testing.T) { + var err error + + // Create test context with flags and arguments. + ctx := NewTestContext([]string{"mod", "--regenerate", "cs7pvt5h8rw9aaqj"}) + + // Run command with test context. + output := capture.Output(func() { + err = ClientsModCommand.Run(ctx) + }) + + // Check command output for plausibility. + //t.Logf(output) + assert.NoError(t, err) + assert.Contains(t, output, "Client Secret") + }) +}