2020-05-26 15:15:14 +02:00
|
|
|
package workers
|
|
|
|
|
|
|
|
import (
|
2020-07-13 18:54:32 +02:00
|
|
|
"strings"
|
2020-05-26 15:15:14 +02:00
|
|
|
"testing"
|
2020-12-11 22:09:11 +01:00
|
|
|
"time"
|
2020-05-26 15:15:14 +02:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
|
|
|
"github.com/photoprism/photoprism/internal/mutex"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2020-05-26 19:27:29 +02:00
|
|
|
func TestPrism_Start(t *testing.T) {
|
2020-05-26 15:15:14 +02:00
|
|
|
conf := config.TestConfig()
|
|
|
|
|
2020-05-30 14:52:47 +02:00
|
|
|
t.Logf("database-dsn: %s", conf.DatabaseDsn())
|
|
|
|
|
2020-06-29 13:35:38 +02:00
|
|
|
worker := NewMeta(conf)
|
2020-05-26 15:15:14 +02:00
|
|
|
|
2020-06-29 13:35:38 +02:00
|
|
|
assert.IsType(t, &Meta{}, worker)
|
2020-05-26 15:15:14 +02:00
|
|
|
|
2020-06-29 13:35:38 +02:00
|
|
|
if err := mutex.MetaWorker.Start(); err != nil {
|
2020-05-26 15:15:14 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-12-11 22:09:11 +01:00
|
|
|
if err := worker.Start(time.Second); err == nil {
|
2020-05-26 15:15:14 +02:00
|
|
|
t.Fatal("error expected")
|
|
|
|
}
|
|
|
|
|
2020-06-29 13:35:38 +02:00
|
|
|
mutex.MetaWorker.Stop()
|
2020-05-26 19:27:29 +02:00
|
|
|
|
2020-12-11 22:09:11 +01:00
|
|
|
if err := worker.Start(time.Second); err != nil {
|
2020-05-26 19:27:29 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-05-26 15:15:14 +02:00
|
|
|
}
|
2020-07-13 16:12:32 +02:00
|
|
|
|
|
|
|
func TestMeta_originalsPath(t *testing.T) {
|
|
|
|
conf := config.TestConfig()
|
|
|
|
|
|
|
|
worker := NewMeta(conf)
|
|
|
|
|
|
|
|
assert.IsType(t, &Meta{}, worker)
|
2020-07-13 18:54:32 +02:00
|
|
|
assert.True(t, strings.HasSuffix(worker.originalsPath(), "testdata/originals"))
|
2020-07-13 16:12:32 +02:00
|
|
|
}
|