common_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. flags uint32
  12. options []Option
  13. closedCh chan struct{}
  14. closedErr error
  15. }
  16. func newTestModel() *TestModel {
  17. return &TestModel{
  18. closedCh: make(chan struct{}),
  19. }
  20. }
  21. func (t *TestModel) Index(deviceID DeviceID, folder string, files []FileInfo, flags uint32, options []Option) {
  22. }
  23. func (t *TestModel) IndexUpdate(deviceID DeviceID, folder string, files []FileInfo, flags uint32, options []Option) {
  24. }
  25. func (t *TestModel) Request(deviceID DeviceID, folder, name string, offset int64, hash []byte, flags uint32, options []Option, buf []byte) error {
  26. t.folder = folder
  27. t.name = name
  28. t.offset = offset
  29. t.size = len(buf)
  30. t.hash = hash
  31. t.flags = flags
  32. t.options = options
  33. copy(buf, t.data)
  34. return nil
  35. }
  36. func (t *TestModel) Close(deviceID DeviceID, err error) {
  37. t.closedErr = err
  38. close(t.closedCh)
  39. }
  40. func (t *TestModel) ClusterConfig(deviceID DeviceID, config ClusterConfigMessage) {
  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. }