mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 19:29:15 +00:00
* names, constants of reusable strings, removed unneeded `if`, replaced deprecated imports * more deprecated imports replaced * What is this?)) * Fix a path and quote a var in Dockerfile * Addressing review comments --------- Co-authored-by: Konstantin Koval <kkb@ukr.net>
75 lines
1.6 KiB
Go
75 lines
1.6 KiB
Go
package scanner_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/photoview/photoview/api/graphql/models"
|
|
"github.com/photoview/photoview/api/scanner"
|
|
"github.com/photoview/photoview/api/test_utils"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
const testDataPath = "./test_data"
|
|
|
|
func TestNewRootPath(t *testing.T) {
|
|
db := test_utils.DatabaseTest(t)
|
|
|
|
user := models.User{
|
|
Username: "user1",
|
|
}
|
|
|
|
if !assert.NoError(t, db.Save(&user).Error) {
|
|
return
|
|
}
|
|
|
|
t.Run("Insert valid root album", func(t *testing.T) {
|
|
album, err := scanner.NewRootAlbum(db, testDataPath, &user)
|
|
if !assert.NoError(t, err) {
|
|
return
|
|
}
|
|
|
|
assert.NotNil(t, album)
|
|
assert.Contains(t, album.Path, "/api/scanner/test_data")
|
|
assert.NotEmpty(t, album.Owners)
|
|
})
|
|
|
|
t.Run("Insert duplicate root album", func(t *testing.T) {
|
|
|
|
_, err := scanner.NewRootAlbum(db, testDataPath, &user)
|
|
|
|
assert.Error(t, err)
|
|
assert.Contains(t, err.Error(), "user already owns a path containing this path:")
|
|
})
|
|
|
|
t.Run("Insert invalid root album", func(t *testing.T) {
|
|
|
|
_, err := scanner.NewRootAlbum(db, "./invalid_path", &user)
|
|
|
|
assert.Error(t, err)
|
|
assert.Equal(t, err.Error(), "invalid root path")
|
|
})
|
|
|
|
t.Run("Add existing root album to new user", func(t *testing.T) {
|
|
|
|
user2 := models.User{
|
|
Username: "user2",
|
|
}
|
|
|
|
if !assert.NoError(t, db.Save(&user2).Error) {
|
|
return
|
|
}
|
|
|
|
album, err := scanner.NewRootAlbum(db, testDataPath, &user2)
|
|
if !assert.NoError(t, err) {
|
|
return
|
|
}
|
|
|
|
assert.NotNil(t, album)
|
|
assert.Contains(t, album.Path, "/api/scanner/test_data")
|
|
|
|
ownerCount := db.Model(&album).Association("Owners").Count()
|
|
assert.EqualValues(t, 2, ownerCount)
|
|
})
|
|
|
|
}
|