Import missing artist portraits from uploaded album folders
ci / module boundaries / boundaries (push) Successful in 6s
ci / contract / contract (сгенерированный код совпадает с openapi.yaml) (push) Successful in 2m1s
ci / ts / ts (packages + web) (push) Failing after 5m13s
ci / api / api (push) Successful in 41s
ci / db / db (push) Failing after 1m33s
ci / mobile / mobile (Metro-бандл Android) (push) Successful in 2m25s
ci / docker / docker (образы собираются — их сервер собирает сам при обновлении) (push) Successful in 2m19s
ci / module boundaries / boundaries (push) Successful in 6s
ci / contract / contract (сгенерированный код совпадает с openapi.yaml) (push) Successful in 2m1s
ci / ts / ts (packages + web) (push) Failing after 5m13s
ci / api / api (push) Successful in 41s
ci / db / db (push) Failing after 1m33s
ci / mobile / mobile (Metro-бандл Android) (push) Successful in 2m25s
ci / docker / docker (образы собираются — их сервер собирает сам при обновлении) (push) Successful in 2m19s
This commit is contained in:
1 parent
fd17c06397
commit
82bf015283
23 files changed
+829
-317
No files matched your search
@@ -0,0 +1,69 @@
|
||||
package library
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type portraitStore struct {
|
||||
id uuid.UUID
|
||||
err error
|
||||
saved uuid.UUID
|
||||
key string
|
||||
}
|
||||
|
||||
func (s *portraitStore) ArtistWithoutImageForFile(context.Context, uuid.UUID) (uuid.UUID, error) {
|
||||
return s.id, s.err
|
||||
}
|
||||
func (s *portraitStore) SetArtistImageIfMissing(_ context.Context, id uuid.UUID, key string) error {
|
||||
s.saved, s.key = id, key
|
||||
return nil
|
||||
}
|
||||
|
||||
type portraitRenderer struct {
|
||||
data []byte
|
||||
err error
|
||||
}
|
||||
|
||||
func (r *portraitRenderer) StoreImage(_ context.Context, data []byte) (string, error) {
|
||||
r.data = data
|
||||
return "portrait-key", r.err
|
||||
}
|
||||
|
||||
func TestArtistPortraitOnlyRendersForAnArtistWithoutImage(t *testing.T) {
|
||||
for _, scenario := range []string{"new portrait", "already has image", "lookup failure", "render failure"} {
|
||||
t.Run(scenario, func(t *testing.T) {
|
||||
st := &portraitStore{id: uuid.New()}
|
||||
renderer := &portraitRenderer{}
|
||||
switch scenario {
|
||||
case "already has image":
|
||||
st.err = ErrNotFound
|
||||
case "lookup failure":
|
||||
st.err = errors.New("database unavailable")
|
||||
case "render failure":
|
||||
renderer.err = errors.New("invalid image")
|
||||
}
|
||||
images := &ArtistImages{store: st, images: renderer}
|
||||
err := images.ApplyArtistImage(context.Background(), uuid.New(), []byte("portrait"))
|
||||
if scenario == "lookup failure" || scenario == "render failure" {
|
||||
require.Error(t, err)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
if scenario == "new portrait" {
|
||||
require.Equal(t, st.id, st.saved)
|
||||
require.Equal(t, "portrait-key", st.key)
|
||||
require.Equal(t, []byte("portrait"), renderer.data)
|
||||
} else {
|
||||
require.Equal(t, uuid.Nil, st.saved)
|
||||
}
|
||||
if scenario == "already has image" || scenario == "lookup failure" {
|
||||
require.Nil(t, renderer.data)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user