Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix combination generator in CompoundMultiIndex #108

Merged
merged 4 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.1

references:
images:
go: &GOLANG_IMAGE docker.mirror.hashicorp.services/circleci/golang:1.15.3
go: &GOLANG_IMAGE docker.mirror.hashicorp.services/circleci/golang:1.16.7

# reusable 'executor' object for jobs
executors:
Expand Down
4 changes: 3 additions & 1 deletion index.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,9 @@ forloop:
if depth == len(builder)-1 {
// These are the "leaves", so append directly
for _, v := range builder[depth] {
out = append(out, append(currPrefix, v...))
outcome := make([]byte, len(currPrefix))
copy(outcome, currPrefix)
out = append(out, append(outcome, v...))
}
return
}
Expand Down
42 changes: 42 additions & 0 deletions index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
crand "crypto/rand"
"encoding/binary"
"fmt"
"reflect"
"sort"
"strings"
"testing"
Expand Down Expand Up @@ -1314,3 +1315,44 @@ func TestCompoundIndex_PrefixFromArgs(t *testing.T) {
t.Fatalf("expected an error when passing too many arguments")
}
}

func TestCompoundMultiIndex_FromObject(t *testing.T) {
// handle sub-indexer case unique to MultiIndexer
obj := &TestObject{
ID: "obj1-uuid",
Foo: "Foo1",
Baz: "yep",
Qux: []string{"Test", "Test2"},
QuxEmpty: []string{"Qux", "Qux2"},
}
indexer := &CompoundMultiIndex{
Indexes: []Indexer{
&StringFieldIndex{Field: "Foo"},
&StringSliceFieldIndex{Field: "Qux"},
&StringSliceFieldIndex{Field: "QuxEmpty"},
},
}

ok, vals, err := indexer.FromObject(obj)
if err != nil {
t.Fatalf("err: %v", err)
}
if !ok {
t.Fatalf("should be ok")
}
// this goes in between each index prefix to compare them correctly
nilb := string([]byte{0})
want := []string{
"Foo1" + nilb + "Test" + nilb + "Qux" + nilb,
"Foo1" + nilb + "Test" + nilb + "Qux2" + nilb,
"Foo1" + nilb + "Test2" + nilb + "Qux" + nilb,
"Foo1" + nilb + "Test2" + nilb + "Qux2" + nilb,
}
got := make([]string, len(vals))
for i, v := range vals {
got[i] = string(v)
}
if !reflect.DeepEqual(got, want) {
t.Fatalf("\ngot: %+v\nwant: %+v\n", got, want)
}
}