test(upload): move storage task fixtures to in-memory mock

This commit is contained in:
ryan
2026-08-28 18:54:23 +08:00
parent 4d6be2fa77
commit c52b7c4abf
6 changed files with 78 additions and 83 deletions
@@ -13,8 +13,6 @@ import (
"errors"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"sync"
"testing"
@@ -128,13 +126,16 @@ func (m *MockStorageService) Put(_ context.Context, key string, body io.Reader,
return contracts.StoragePutResult{}, err
}
m.objects[key] = data
if strings.HasPrefix(key, "uploads/") {
_ = os.MkdirAll(filepath.Dir(key), 0o755)
_ = os.WriteFile(key, data, 0o644)
}
return contracts.StoragePutResult{Key: key, Bucket: "test-bucket"}, nil
}
// PutRaw seeds an object directly into the in-memory store (test helper, no I/O).
func (m *MockStorageService) PutRaw(key string, data []byte) {
m.mu.Lock()
defer m.mu.Unlock()
m.objects[key] = data
}
// Get retrieves an object from mock storage.
func (m *MockStorageService) Get(_ context.Context, key string) (*contracts.StorageObject, error) {
m.mu.RLock()
@@ -148,15 +149,6 @@ func (m *MockStorageService) Get(_ context.Context, key string) (*contracts.Stor
ContentType: "application/octet-stream",
}, nil
}
if f, err := os.Open(key); err == nil {
info, _ := f.Stat()
return &contracts.StorageObject{
Key: key,
Body: f,
ContentLength: info.Size(),
ContentType: "application/octet-stream",
}, nil
}
return nil, gorm.ErrRecordNotFound
}