common_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright (C) 2014 The Protocol Authors.
  2. package protocol
  3. import "time"
  4. type TestModel struct {
  5. data []byte
  6. folder string
  7. name string
  8. offset int64
  9. size int
  10. hash []byte
  11. fromTemporary bool
  12. closedCh chan struct{}
  13. closedErr error
  14. }
  15. func newTestModel() *TestModel {
  16. return &TestModel{
  17. closedCh: make(chan struct{}),
  18. }
  19. }
  20. func (t *TestModel) Index(deviceID DeviceID, folder string, files []FileInfo) {
  21. }
  22. func (t *TestModel) IndexUpdate(deviceID DeviceID, folder string, files []FileInfo) {
  23. }
  24. func (t *TestModel) Request(deviceID DeviceID, folder, name string, offset int64, hash []byte, fromTemporary bool, buf []byte) error {
  25. t.folder = folder
  26. t.name = name
  27. t.offset = offset
  28. t.size = len(buf)
  29. t.hash = hash
  30. t.fromTemporary = fromTemporary
  31. copy(buf, t.data)
  32. return nil
  33. }
  34. func (t *TestModel) Close(deviceID DeviceID, err error) {
  35. t.closedErr = err
  36. close(t.closedCh)
  37. }
  38. func (t *TestModel) ClusterConfig(deviceID DeviceID, config ClusterConfig) {
  39. }
  40. func (t *TestModel) DownloadProgress(DeviceID, string, []FileDownloadProgressUpdate) {
  41. }
  42. func (t *TestModel) closedError() error {
  43. select {
  44. case <-t.closedCh:
  45. return t.closedErr
  46. case <-time.After(1 * time.Second):
  47. return nil // Timeout
  48. }
  49. }