mirror of
https://github.com/usememos/memos.git
synced 2024-12-20 17:51:50 +03:00
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
|
package teststore
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/require"
|
||
|
"github.com/usememos/memos/api"
|
||
|
)
|
||
|
|
||
|
func TestResourceStore(t *testing.T) {
|
||
|
ctx := context.Background()
|
||
|
store := NewTestingStore(ctx, t)
|
||
|
_, err := store.CreateResource(ctx, &api.ResourceCreate{
|
||
|
CreatorID: 101,
|
||
|
Filename: "test.epub",
|
||
|
Blob: []byte("test"),
|
||
|
InternalPath: "",
|
||
|
ExternalLink: "",
|
||
|
Type: "application/epub+zip",
|
||
|
Size: 637607,
|
||
|
PublicID: "a02748e2-9b56-46b2-8b1f-72d686d52f77",
|
||
|
})
|
||
|
require.NoError(t, err)
|
||
|
|
||
|
correctFilename := "test.epub"
|
||
|
incorrectFilename := "test.png"
|
||
|
res, err := store.FindResource(ctx, &api.ResourceFind{
|
||
|
Filename: &correctFilename,
|
||
|
})
|
||
|
require.NoError(t, err)
|
||
|
require.Equal(t, correctFilename, res.Filename)
|
||
|
require.Equal(t, 1, res.ID)
|
||
|
_, err = store.FindResource(ctx, &api.ResourceFind{
|
||
|
Filename: &incorrectFilename,
|
||
|
})
|
||
|
require.Error(t, err)
|
||
|
|
||
|
correctCreatorID := 101
|
||
|
incorrectCreatorID := 102
|
||
|
_, err = store.FindResource(ctx, &api.ResourceFind{
|
||
|
CreatorID: &correctCreatorID,
|
||
|
})
|
||
|
require.NoError(t, err)
|
||
|
_, err = store.FindResource(ctx, &api.ResourceFind{
|
||
|
CreatorID: &incorrectCreatorID,
|
||
|
})
|
||
|
require.Error(t, err)
|
||
|
|
||
|
err = store.DeleteResource(ctx, &api.ResourceDelete{
|
||
|
ID: 1,
|
||
|
})
|
||
|
require.NoError(t, err)
|
||
|
err = store.DeleteResource(ctx, &api.ResourceDelete{
|
||
|
ID: 2,
|
||
|
})
|
||
|
require.Error(t, err)
|
||
|
}
|