2023-04-13 14:55:18 +03:00
|
|
|
package teststore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2023-07-05 19:01:40 +03:00
|
|
|
"github.com/usememos/memos/store"
|
2023-04-13 14:55:18 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestResourceStore(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
2023-07-05 19:01:40 +03:00
|
|
|
ts := NewTestingStore(ctx, t)
|
2023-07-06 16:56:42 +03:00
|
|
|
_, err := ts.CreateResource(ctx, &store.Resource{
|
2023-04-13 14:55:18 +03:00
|
|
|
CreatorID: 101,
|
|
|
|
Filename: "test.epub",
|
|
|
|
Blob: []byte("test"),
|
|
|
|
InternalPath: "",
|
|
|
|
ExternalLink: "",
|
|
|
|
Type: "application/epub+zip",
|
|
|
|
Size: 637607,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
correctFilename := "test.epub"
|
|
|
|
incorrectFilename := "test.png"
|
2023-07-05 19:01:40 +03:00
|
|
|
res, err := ts.GetResource(ctx, &store.FindResource{
|
2023-04-13 14:55:18 +03:00
|
|
|
Filename: &correctFilename,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, correctFilename, res.Filename)
|
|
|
|
require.Equal(t, 1, res.ID)
|
2023-07-05 19:01:40 +03:00
|
|
|
notFoundResource, err := ts.GetResource(ctx, &store.FindResource{
|
2023-04-13 14:55:18 +03:00
|
|
|
Filename: &incorrectFilename,
|
|
|
|
})
|
2023-07-05 19:01:40 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, notFoundResource)
|
2023-04-13 14:55:18 +03:00
|
|
|
|
|
|
|
correctCreatorID := 101
|
|
|
|
incorrectCreatorID := 102
|
2023-07-05 19:01:40 +03:00
|
|
|
_, err = ts.GetResource(ctx, &store.FindResource{
|
2023-04-13 14:55:18 +03:00
|
|
|
CreatorID: &correctCreatorID,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2023-07-05 19:01:40 +03:00
|
|
|
notFoundResource, err = ts.GetResource(ctx, &store.FindResource{
|
2023-04-13 14:55:18 +03:00
|
|
|
CreatorID: &incorrectCreatorID,
|
|
|
|
})
|
2023-07-05 19:01:40 +03:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Nil(t, notFoundResource)
|
2023-04-13 14:55:18 +03:00
|
|
|
|
2023-07-06 16:56:42 +03:00
|
|
|
err = ts.DeleteResource(ctx, &store.DeleteResource{
|
2023-04-13 14:55:18 +03:00
|
|
|
ID: 1,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2023-07-06 16:56:42 +03:00
|
|
|
err = ts.DeleteResource(ctx, &store.DeleteResource{
|
2023-04-13 14:55:18 +03:00
|
|
|
ID: 2,
|
|
|
|
})
|
2023-07-05 19:01:40 +03:00
|
|
|
require.NoError(t, err)
|
2023-04-13 14:55:18 +03:00
|
|
|
}
|