Tests: Add unit tests
This commit is contained in:
parent
86d2ce0772
commit
d478f08718
6 changed files with 210 additions and 1 deletions
52
internal/commands/auth_reset_test.go
Normal file
52
internal/commands/auth_reset_test.go
Normal 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")
|
||||
})
|
||||
}
|
|
@ -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) {
|
||||
|
|
52
internal/commands/clients_reset_test.go
Normal file
52
internal/commands/clients_reset_test.go
Normal 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")
|
||||
})
|
||||
}
|
27
internal/commands/users_legacy_test.go
Normal file
27
internal/commands/users_legacy_test.go
Normal 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 |")
|
||||
})
|
||||
}
|
52
internal/commands/users_reset_test.go
Normal file
52
internal/commands/users_reset_test.go
Normal 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")
|
||||
})
|
||||
}
|
25
internal/commands/version_test.go
Normal file
25
internal/commands/version_test.go
Normal 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")
|
||||
}
|
Loading…
Reference in a new issue