storage_test.go 1009 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package teststore
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/stretchr/testify/require"
  6. "github.com/usememos/memos/store"
  7. )
  8. func TestStorageStore(t *testing.T) {
  9. ctx := context.Background()
  10. ts := NewTestingStore(ctx, t)
  11. storage, err := ts.CreateStorage(ctx, &store.Storage{
  12. Name: "test_storage",
  13. Type: "S3",
  14. Config: "{}",
  15. })
  16. require.NoError(t, err)
  17. newStorageName := "new_storage_name"
  18. updatedStorage, err := ts.UpdateStorage(ctx, &store.UpdateStorage{
  19. ID: storage.ID,
  20. Name: &newStorageName,
  21. })
  22. require.NoError(t, err)
  23. require.Equal(t, newStorageName, updatedStorage.Name)
  24. storageList, err := ts.ListStorages(ctx, &store.FindStorage{})
  25. require.NoError(t, err)
  26. require.Equal(t, 1, len(storageList))
  27. require.Equal(t, updatedStorage, storageList[0])
  28. err = ts.DeleteStorage(ctx, &store.DeleteStorage{
  29. ID: storage.ID,
  30. })
  31. require.NoError(t, err)
  32. storageList, err = ts.ListStorages(ctx, &store.FindStorage{})
  33. require.NoError(t, err)
  34. require.Equal(t, 0, len(storageList))
  35. }