lib/protocol: Further interface refactor (#9396)

This is a symmetric change to #9375 -- where that PR changed the
protocol->model interface, this changes the model->protocol one.
This commit is contained in:
Jakob Borg
2024-08-24 12:45:10 +02:00
committed by GitHub
parent 7df75e681d
commit 5342bec1b7
13 changed files with 170 additions and 221 deletions
+9 -7
View File
@@ -30,8 +30,8 @@ func newFakeConnection(id protocol.DeviceID, model Model) *fakeConnection {
model: model,
closed: make(chan struct{}),
}
f.RequestCalls(func(ctx context.Context, folder, name string, blockNo int, offset int64, size int, hash []byte, weakHash uint32, fromTemporary bool) ([]byte, error) {
return f.fileData[name], nil
f.RequestCalls(func(ctx context.Context, req *protocol.Request) ([]byte, error) {
return f.fileData[req.Name], nil
})
f.DeviceIDReturns(id)
f.ConnectionIDReturns(rand.String(16))
@@ -60,14 +60,16 @@ type fakeConnection struct {
}
func (f *fakeConnection) setIndexFn(fn func(_ context.Context, folder string, fs []protocol.FileInfo) error) {
f.IndexCalls(fn)
f.IndexUpdateCalls(fn)
f.IndexCalls(func(ctx context.Context, idx *protocol.Index) error { return fn(ctx, idx.Folder, idx.Files) })
f.IndexUpdateCalls(func(ctx context.Context, idxUp *protocol.IndexUpdate) error {
return fn(ctx, idxUp.Folder, idxUp.Files)
})
}
func (f *fakeConnection) DownloadProgress(_ context.Context, folder string, updates []protocol.FileDownloadProgressUpdate) {
func (f *fakeConnection) DownloadProgress(_ context.Context, dp *protocol.DownloadProgress) {
f.downloadProgressMessages = append(f.downloadProgressMessages, downloadProgressMessage{
folder: folder,
updates: updates,
folder: dp.Folder,
updates: dp.Updates,
})
}