Backend: Add unit tests for internal/workers

This commit is contained in:
Theresa Gresch 2020-07-13 16:44:17 +02:00
parent 2bcb954266
commit dac846ba01
2 changed files with 64 additions and 0 deletions

View file

@ -51,6 +51,20 @@ var FileSyncFixtures = FileSyncMap{
CreatedAt: time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC),
UpdatedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
},
"FileSync3": {
FileID: 1000000,
AccountID: 1000000,
RemoteName: "name for remote sync",
Status: "new",
Error: "",
Errors: 0,
File: &FileFixturesExampleJPG,
Account: &AccountFixtureWebdavDummy,
RemoteDate: time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC),
RemoteSize: int64(60),
CreatedAt: time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC),
UpdatedAt: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
},
}
// CreateFileSyncFixtures inserts known entities into the database for testing.

View file

@ -0,0 +1,50 @@
package workers
import (
"github.com/photoprism/photoprism/internal/entity"
"testing"
"github.com/photoprism/photoprism/internal/config"
"github.com/stretchr/testify/assert"
)
func TestSync_download(t *testing.T) {
conf := config.TestConfig()
t.Logf("database-dsn: %s", conf.DatabaseDsn())
worker := NewSync(conf)
assert.IsType(t, &Sync{}, worker)
account := entity.AccountFixtureWebdavDummy
complete, err := worker.download(account)
if err != nil {
t.Fatal(err)
}
assert.True(t, complete)
}
func TestSync_downloadPath(t *testing.T) {
conf := config.TestConfig()
worker := NewSync(conf)
assert.IsType(t, &Sync{}, worker)
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/temp/sync", worker.downloadPath())
}
func TestSync_relatedDownloads(t *testing.T) {
conf := config.TestConfig()
worker := NewSync(conf)
account := entity.AccountFixtureWebdavDummy
assert.IsType(t, &Sync{}, worker)
result, err := worker.relatedDownloads(account)
if err != nil {
t.Fatal(err)
}
assert.IsType(t, Downloads{}, result)
}