photoprism/internal/commands/index_test.go

55 lines
953 B
Go
Raw Normal View History

2021-09-30 15:50:10 +02:00
package commands
import (
"testing"
"time"
2021-09-30 15:50:10 +02:00
"github.com/leandro-lugaresi/hub"
"github.com/stretchr/testify/assert"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/event"
2021-09-30 15:50:10 +02:00
"github.com/photoprism/photoprism/pkg/capture"
)
func TestIndexCommand(t *testing.T) {
var err error
ctx := config.CliTestContext()
s := event.Subscribe("log.info")
defer event.Unsubscribe(s)
var l string
2021-09-30 15:50:10 +02:00
assert.IsType(t, hub.Subscription{}, s)
go func() {
for msg := range s.Receiver {
l += msg.Fields["message"].(string) + "\n"
2021-09-30 15:50:10 +02:00
}
}()
stdout := capture.Output(func() {
err = IndexCommand.Run(ctx)
})
if err != nil {
t.Fatal(err)
}
if stdout != "" {
t.Logf("stdout: %s", stdout)
2021-09-30 15:50:10 +02:00
}
time.Sleep(time.Second)
if l != "" {
2021-09-30 15:50:10 +02:00
// Expected index command output.
assert.NotContains(t, l, "error")
assert.Contains(t, l, "found no .ppignore file")
2021-09-30 15:50:10 +02:00
} else {
t.Fatal("log output missing")
}
}