diff --git a/ingest_test.go b/ingest_test.go index 637a78d5e2..b4f34a2d65 100644 --- a/ingest_test.go +++ b/ingest_test.go @@ -1897,16 +1897,21 @@ func TestIngestExternal(t *testing.T) { func TestIngestMemtableOverlaps(t *testing.T) { comparers := []Comparer{ - {Name: "default", Compare: DefaultComparer.Compare, FormatKey: DefaultComparer.FormatKey}, { - Name: "reverse", - Compare: func(a, b []byte) int { return DefaultComparer.Compare(b, a) }, - FormatKey: DefaultComparer.FormatKey, + Name: "default", + Compare: DefaultComparer.Compare, + }, + { + Name: "reverse", + Compare: func(a, b []byte) int { return DefaultComparer.Compare(b, a) }, }, } m := make(map[string]*Comparer) for i := range comparers { c := &comparers[i] + c.AbbreviatedKey = func(key []byte) uint64 { panic("unimplemented") } + c.Successor = func(dst, a []byte) []byte { panic("unimplemented") } + c.Separator = func(dst, a, b []byte) []byte { panic("unimplemented") } m[c.Name] = c } diff --git a/internal/base/comparer.go b/internal/base/comparer.go index bc5b1a3055..40628cb819 100644 --- a/internal/base/comparer.go +++ b/internal/base/comparer.go @@ -161,6 +161,9 @@ func (c *Comparer) EnsureDefaults() *Comparer { if c == nil { return DefaultComparer } + if c.Compare == nil || c.AbbreviatedKey == nil || c.Separator == nil || c.Successor == nil || c.Name == "" { + panic("invalid Comparer: mandatory field not set") + } if c.Equal != nil && c.FormatKey != nil { return c } diff --git a/open_test.go b/open_test.go index 569e17fe02..683bc5508c 100644 --- a/open_test.go +++ b/open_test.go @@ -348,8 +348,11 @@ func TestOpenOptionsCheck(t *testing.T) { require.NoError(t, err) require.NoError(t, d.Close()) + fooCmp := *base.DefaultComparer + fooCmp.Name = "foo" + opts = &Options{ - Comparer: &Comparer{Name: "foo"}, + Comparer: &fooCmp, FS: mem, } _, err = Open("", opts)