refactor: add needed helper functions and overrides to properly compare the maps

This commit is contained in:
Derrick Hammer 2024-01-05 06:16:04 -05:00
parent 15b6a0dc19
commit 951f0062da
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 38 additions and 3 deletions

View File

@ -3,15 +3,50 @@ package metadata
import (
"encoding/json"
"fmt"
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
cmp "github.com/LumeWeb/go-cmp"
"github.com/emirpasic/gods/maps/linkedhashmap"
cmp "github.com/google/go-cmp/cmp"
"github.com/vmihailenco/msgpack/v5"
"os"
"path/filepath"
"reflect"
"testing"
)
func isEqual(sizeFunc1, sizeFunc2 func() int, iteratorFunc1, iteratorFunc2 func() linkedhashmap.Iterator) bool {
if sizeFunc1() != sizeFunc2() {
return false
}
iter1 := iteratorFunc1()
iter2 := iteratorFunc2()
for iter1.Next() {
iter2.Next()
if iter1.Key() != iter2.Key() {
return false
}
if !cmp.Equal(iter1.Value(), iter2.Value()) {
return false
}
}
return true
}
func (frm fileReferenceMap) Equal(other fileReferenceMap) bool {
return isEqual(frm.Size, other.Size, frm.Iterator, other.Iterator)
}
func (frm fileHistoryMap) Equal(other fileHistoryMap) bool {
return isEqual(frm.Size, other.Size, frm.Iterator, other.Iterator)
}
func (drm directoryReferenceMap) Equal(other directoryReferenceMap) bool {
return isEqual(drm.Size, other.Size, drm.Iterator, other.Iterator)
}
func (ext extMap) Equal(other extMap) bool {
return isEqual(ext.Size, other.Size, ext.Iterator, other.Iterator)
}
func readFile(filename string) []byte {
filePath := filepath.Join("testdata", filename)
data, err := os.ReadFile(filePath)