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