fix: add FileReference Equal

This commit is contained in:
Derrick Hammer 2024-01-18 09:15:07 -05:00
parent 3e76519091
commit 68200ae626
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 29 additions and 0 deletions

View File

@ -45,6 +45,9 @@ func (drm directoryReferenceMap) Equal(other directoryReferenceMap) bool {
func (ext ExtMap) Equal(other ExtMap) bool {
return isEqual(ext.Size, other.Size, ext.Iterator, other.Iterator)
}
func (fr FileReference) Equal(other FileReference) bool {
return fr.File.CID().Equals(other.File.CID())
}
func readFile(filename string) []byte {
filePath := filepath.Join("testdata", filename)
@ -68,6 +71,32 @@ func getDirectoryMeta() *DirectoryMetadata {
return &dir
}
func TestDirectoryMetadata_DecodeJSON(t *testing.T) {
tests := []struct {
name string
wantErr bool
}{
{
name: "Decode",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
jsonDm := getDirectoryMeta()
dm := &DirectoryMetadata{}
if err := msgpack.Unmarshal(readFile("directory.bin"), dm); (err != nil) != tt.wantErr {
t.Errorf("DecodeMsgpack() error = %v, wantErr %v", err, tt.wantErr)
}
if !cmp.Equal(jsonDm, dm) {
t.Errorf("DecodeMsgpack() error = %v, wantErr %v", "msgpack does not match json", tt.wantErr)
}
})
}
}
func TestDirectoryMetadata_DecodeMsgpack(t *testing.T) {
tests := []struct {
name string