Backend: Add unit tests for internal/workers
This commit is contained in:
parent
2bcb954266
commit
dac846ba01
|
@ -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.
|
||||
|
|
50
internal/workers/sync_download_test.go
Normal file
50
internal/workers/sync_download_test.go
Normal 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)
|
||||
}
|
Loading…
Reference in a new issue