filer_notify_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package filer2
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  6. "github.com/golang/protobuf/proto"
  7. )
  8. func TestProtoMarshalText(t *testing.T) {
  9. oldEntry := &Entry{
  10. FullPath: FullPath("/this/path/to"),
  11. Attr: Attr{
  12. Mtime: time.Now(),
  13. Mode: 0644,
  14. Uid: 1,
  15. Mime: "text/json",
  16. TtlSec: 25,
  17. },
  18. Chunks: []*filer_pb.FileChunk{
  19. &filer_pb.FileChunk{
  20. FileId: "234,2423423422",
  21. Offset: 234234,
  22. Size: 234,
  23. Mtime: 12312423,
  24. ETag: "2342342354",
  25. SourceFileId: "23234,2342342342",
  26. },
  27. },
  28. }
  29. notification := &filer_pb.EventNotification{
  30. OldEntry: oldEntry.ToProtoEntry(),
  31. NewEntry: nil,
  32. DeleteChunks: true,
  33. }
  34. text := proto.MarshalTextString(notification)
  35. notification2 := &filer_pb.EventNotification{}
  36. proto.UnmarshalText(text, notification2)
  37. if notification2.OldEntry.Chunks[0].SourceFileId != notification.OldEntry.Chunks[0].SourceFileId {
  38. t.Fatalf("marshal/unmarshal error: %s", text)
  39. }
  40. println(text)
  41. }