filer_notify_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package filer
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  6. "github.com/seaweedfs/seaweedfs/weed/util"
  7. "google.golang.org/protobuf/proto"
  8. )
  9. func TestProtoMarshal(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. {
  21. FileId: "234,2423423422",
  22. Offset: 234234,
  23. Size: 234,
  24. ModifiedTsNs: 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.Marshal(notification)
  36. notification2 := &filer_pb.EventNotification{}
  37. proto.Unmarshal(text, notification2)
  38. if notification2.OldEntry.GetChunks()[0].SourceFileId != notification.OldEntry.GetChunks()[0].SourceFileId {
  39. t.Fatalf("marshal/unmarshal error: %s", text)
  40. }
  41. println(string(text))
  42. }