Handler_test.go 1019 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package server
  2. import (
  3. "encoding/binary"
  4. "file-manger-server/db"
  5. "testing"
  6. )
  7. func TestHandlerReceiveFile(t *testing.T) {
  8. db.Open()
  9. bytes := []byte{
  10. 0x01,
  11. }
  12. for i := 0; i < 32; i++ {
  13. bytes = append(bytes, byte(i))
  14. }
  15. var fileName = "test.txt"
  16. //文件名长度
  17. bytes = binary.BigEndian.AppendUint32(bytes, uint32(len(fileName)))
  18. //文件名
  19. bytes = append(bytes, []byte(fileName)...)
  20. //文件大小
  21. bytes = binary.BigEndian.AppendUint64(bytes, uint64(10))
  22. var path = "./file/" + fileName
  23. bytes = binary.BigEndian.AppendUint32(bytes, uint32(len(path)))
  24. //文件路径
  25. bytes = append(bytes, []byte(path)...)
  26. //分片大小
  27. bytes = binary.BigEndian.AppendUint32(bytes, uint32(9))
  28. //创建时间
  29. bytes = binary.BigEndian.AppendUint64(bytes, uint64(999))
  30. //修改时间
  31. bytes = binary.BigEndian.AppendUint64(bytes, uint64(9999))
  32. //最后访问时间
  33. bytes = binary.BigEndian.AppendUint64(bytes, uint64(99999))
  34. bytes = append(bytes, []byte("1234567890")...)
  35. HandlerReceiveFile(nil, bytes)
  36. }