2020-09-01 15:21:19 +08:00
|
|
|
package filer
|
2018-10-31 16:11:19 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
2020-03-23 15:01:34 +08:00
|
|
|
|
2022-08-18 03:05:07 +08:00
|
|
|
"google.golang.org/protobuf/proto"
|
2018-10-31 16:11:19 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestProtoMarshalText(t *testing.T) {
|
|
|
|
|
|
|
|
oldEntry := &Entry{
|
2020-03-23 15:01:34 +08:00
|
|
|
FullPath: util.FullPath("/this/path/to"),
|
2018-10-31 16:11:19 +08:00
|
|
|
Attr: Attr{
|
|
|
|
Mtime: time.Now(),
|
|
|
|
Mode: 0644,
|
|
|
|
Uid: 1,
|
|
|
|
Mime: "text/json",
|
|
|
|
TtlSec: 25,
|
|
|
|
},
|
|
|
|
Chunks: []*filer_pb.FileChunk{
|
|
|
|
&filer_pb.FileChunk{
|
|
|
|
FileId: "234,2423423422",
|
|
|
|
Offset: 234234,
|
|
|
|
Size: 234,
|
|
|
|
Mtime: 12312423,
|
|
|
|
ETag: "2342342354",
|
|
|
|
SourceFileId: "23234,2342342342",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
notification := &filer_pb.EventNotification{
|
2018-11-04 03:43:45 +08:00
|
|
|
OldEntry: oldEntry.ToProtoEntry(),
|
|
|
|
NewEntry: nil,
|
2018-10-31 16:11:19 +08:00
|
|
|
DeleteChunks: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
text := proto.MarshalTextString(notification)
|
|
|
|
|
|
|
|
notification2 := &filer_pb.EventNotification{}
|
|
|
|
proto.UnmarshalText(text, notification2)
|
|
|
|
|
|
|
|
if notification2.OldEntry.Chunks[0].SourceFileId != notification.OldEntry.Chunks[0].SourceFileId {
|
|
|
|
t.Fatalf("marshal/unmarshal error: %s", text)
|
|
|
|
}
|
|
|
|
|
|
|
|
println(text)
|
|
|
|
|
|
|
|
}
|