schema endpoint doesn't return internal fields

This commit is contained in:
Matt Jaffee 2018-12-17 16:01:32 -06:00
parent 45cd48c1b7
commit ef7f04c09d
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF
2 changed files with 21 additions and 1 deletions

View file

@ -18,6 +18,7 @@ import (
"context"
"fmt"
"reflect"
"strings"
"testing"
"github.com/pilosa/pilosa"
@ -48,7 +49,7 @@ func TestAPI_Import(t *testing.T) {
index := "rick"
field := "f"
_, err := m0.API.CreateIndex(ctx, index, pilosa.IndexOptions{Keys: true})
_, err := m0.API.CreateIndex(ctx, index, pilosa.IndexOptions{Keys: true, TrackExistence: true})
if err != nil {
t.Fatalf("creating index: %v", err)
}
@ -99,6 +100,22 @@ func TestAPI_Import(t *testing.T) {
} else if keys := res.Results[0].(*pilosa.Row).Keys; !reflect.DeepEqual(keys, colKeys) {
t.Fatalf("unexpected column keys: %+v", keys)
}
})
// Relies on the previous test creating an index with TrackExistence and
// adding some data.
t.Run("SchemaHasNoExists", func(t *testing.T) {
schema := m1.API.Schema(context.Background())
for _, f := range schema[0].Fields {
if f.Name == "_exists" {
t.Fatalf("found _exists field in schema")
}
if strings.HasPrefix(f.Name, "_") {
t.Fatalf("found internal field '%s' in schema output", f.Name)
}
}
})
t.Run("RowKeyColumnID", func(t *testing.T) {

View file

@ -289,6 +289,9 @@ func (h *Holder) limitedSchema() []*IndexInfo {
for _, index := range h.Indexes() {
di := &IndexInfo{Name: index.Name(), Options: index.Options()}
for _, field := range index.Fields() {
if strings.HasPrefix(field.name, "_") {
continue
}
fi := &FieldInfo{Name: field.Name(), Options: field.Options()}
di.Fields = append(di.Fields, fi)
}