mirror of
https://github.com/usememos/memos.git
synced 2024-12-25 12:23:09 +03:00
630d84348e
* add resource unit test * add more resource unit test * change variable name * add more test cases * delete unnecessary line * eslint * add more asset
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)
|
|
}
|