Tests: Add unit tests

This commit is contained in:
graciousgrey 2024-01-25 16:36:38 +01:00
parent 86d2ce0772
commit d478f08718
6 changed files with 210 additions and 1 deletions

View file

@ -0,0 +1,52 @@
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.
ctx0 := NewTestContext([]string{"ls"})
// Run command with test context.
output0 := capture.Output(func() {
err = AuthListCommand.Run(ctx0)
})
// Check command output for plausibility.
// t.Logf(output)
assert.NoError(t, err)
assert.Contains(t, output0, "alice")
assert.Contains(t, output0, "visitor")
// Create test context with flags and arguments.
ctx := NewTestContext([]string{"reset"})
// Run command with test context.
output := capture.Output(func() {
err = AuthResetCommand.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 = AuthListCommand.Run(ctx0)
})
// Check command output for plausibility.
// t.Logf(output)
assert.NoError(t, err)
assert.Contains(t, output1, "alice")
assert.Contains(t, output1, "visitor")
})
}

View file

@ -1,9 +1,10 @@
package commands
import (
"testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert"
"testing"
)
func TestClientsAddCommand(t *testing.T) {

View file

@ -0,0 +1,52 @@
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.
ctx0 := NewTestContext([]string{"ls"})
// Run command with test context.
output0 := capture.Output(func() {
err = ClientsListCommand.Run(ctx0)
})
// Check command output for plausibility.
// t.Logf(output)
assert.NoError(t, err)
assert.Contains(t, output0, "alice")
assert.Contains(t, output0, "metrics")
// Create test context with flags and arguments.
ctx := NewTestContext([]string{"reset"})
// Run command with test context.
output := capture.Output(func() {
err = ClientsResetCommand.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 = ClientsListCommand.Run(ctx0)
})
// Check command output for plausibility.
// t.Logf(output)
assert.NoError(t, err)
assert.Contains(t, output1, "alice")
assert.Contains(t, output1, "metrics")
})
}

View file

@ -0,0 +1,27 @@
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.
ctx := NewTestContext([]string{""})
// Run command with test context.
output := capture.Output(func() {
err = UsersLegacyCommand.Run(ctx)
})
// Check command output for plausibility.
//t.Logf(output)
assert.NoError(t, err)
assert.Contains(t, output, "| ID | UID | Name | User | Email | Admin | Created At |")
})
}

View file

@ -0,0 +1,52 @@
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.
ctx0 := NewTestContext([]string{"ls"})
// Run command with test context.
output0 := capture.Output(func() {
err = UsersListCommand.Run(ctx0)
})
// Check command output for plausibility.
// t.Logf(output)
assert.NoError(t, err)
assert.Contains(t, output0, "alice")
assert.Contains(t, output0, "bob")
// Create test context with flags and arguments.
ctx := NewTestContext([]string{"reset"})
// Run command with test context.
output := capture.Output(func() {
err = UsersResetCommand.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 = UsersListCommand.Run(ctx0)
})
// Check command output for plausibility.
// t.Logf(output)
assert.NoError(t, err)
assert.Contains(t, output1, "alice")
assert.Contains(t, output1, "bob")
})
}

View file

@ -0,0 +1,25 @@
package commands
import (
"testing"
"github.com/photoprism/photoprism/pkg/capture"
"github.com/stretchr/testify/assert"
)
func TestVersionCommand(t *testing.T) {
var err error
// Create test context with flags and arguments.
ctx := NewTestContext([]string{""})
// Run command with test context.
output := capture.Output(func() {
err = VersionCommand.Run(ctx)
})
// Check command output for plausibility.
// t.Logf(output)
assert.NoError(t, err)
assert.Contains(t, output, "test")
}