2021-09-30 15:50:10 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2021-10-01 00:25:31 +02:00
|
|
|
"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"
|
2022-09-02 21:30:50 +02:00
|
|
|
"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)
|
2022-09-02 21:30:50 +02:00
|
|
|
|
|
|
|
var l string
|
2021-09-30 15:50:10 +02:00
|
|
|
|
|
|
|
assert.IsType(t, hub.Subscription{}, s)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
for msg := range s.Receiver {
|
2022-09-02 21:30:50 +02:00
|
|
|
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 != "" {
|
2022-09-02 21:30:50 +02:00
|
|
|
t.Logf("stdout: %s", stdout)
|
2021-09-30 15:50:10 +02:00
|
|
|
}
|
|
|
|
|
2021-10-01 00:25:31 +02:00
|
|
|
time.Sleep(time.Second)
|
|
|
|
|
2022-09-02 21:30:50 +02:00
|
|
|
if l != "" {
|
2021-09-30 15:50:10 +02:00
|
|
|
// Expected index command output.
|
2022-09-02 21:30:50 +02:00
|
|
|
assert.NotContains(t, l, "error")
|
2022-09-14 22:14:17 +02:00
|
|
|
assert.NotContains(t, l, "warning")
|
|
|
|
assert.NotContains(t, l, "failed")
|
|
|
|
assert.Contains(t, l, "closed database connection")
|
2021-09-30 15:50:10 +02:00
|
|
|
} else {
|
|
|
|
t.Fatal("log output missing")
|
|
|
|
}
|
|
|
|
}
|