优化结构
This commit is contained in:
@@ -135,14 +135,26 @@ type mediaUploadRepo struct {
|
||||
chunks []*UploadChunk
|
||||
claimed bool
|
||||
failed bool
|
||||
err error
|
||||
}
|
||||
|
||||
func (r *mediaUploadRepo) FindUploadSession(context.Context, uint) (*UploadSession, error) {
|
||||
if r.err != nil {
|
||||
return nil, r.err
|
||||
}
|
||||
if r.session == nil {
|
||||
return nil, ErrUploadSessionNotFound
|
||||
}
|
||||
return r.session, nil
|
||||
}
|
||||
|
||||
func TestSaveChunkPreservesUploadRepositoryErrors(t *testing.T) {
|
||||
want := errors.New("database unavailable")
|
||||
uc := NewMediaUsecase(&mediaUploadRepo{err: want}, &mediaLimitStorage{}, mediaLimitSettings{max: 10})
|
||||
if err := uc.SaveChunk(context.Background(), 1, 7, 0, md5Text("abc"), strings.NewReader("abc")); !errors.Is(err, want) {
|
||||
t.Fatalf("SaveChunk() error = %v, want %v", err, want)
|
||||
}
|
||||
}
|
||||
func (r *mediaUploadRepo) ClaimUploadSession(context.Context, uint) (bool, error) {
|
||||
return r.claimed, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user