filer_notify_test.go 1.1 KB

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