increase test coverage

This commit is contained in:
Todd Gruben 2022-03-15 11:01:03 -05:00
parent 8c3c774492
commit dfe052aa1a
2 changed files with 31 additions and 9 deletions

View file

@ -19,10 +19,8 @@ import (
pilosa "github.com/molecula/featurebase/v3"
"github.com/molecula/featurebase/v3/logger"
"github.com/molecula/featurebase/v3/pql"
"github.com/molecula/featurebase/v3/server"
"github.com/molecula/featurebase/v3/topology"
"github.com/molecula/featurebase/v3/vprint"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
)
@ -194,13 +192,6 @@ func (cmd *RestoreCommand) restoreSchema(ctx context.Context, primary *topology.
}
for _, field := range index.Fields {
logger.Printf("Create Field %v", field.Name)
if field.Options.Type == pilosa.FieldTypeDecimal {
min, max := pql.MinMax(field.Options.Scale)
scale := field.Options.Scale
vprint.VV("setting MinMax %v %s %s", scale, min, max)
field.Options.Max = max
field.Options.Min = min
}
err = cmd.client.CreateFieldWithOptions(ctx, index.Name, field.Name, field.Options)
if err != nil {
return err

View file

@ -886,6 +886,37 @@ func TestHandler_Endpoints(t *testing.T) {
}
}
})
t.Run("Query decimal field scale only", func(t *testing.T) {
w := httptest.NewRecorder()
fieldName := "f-decimal-scale-only"
h.ServeHTTP(w, test.MustNewHTTPRequest("POST", fmt.Sprintf("/index/i0/field/%s", fieldName),
strings.NewReader(`{"options":{"type":"decimal", "scale": 2}}`)))
if w.Code != gohttp.StatusOK {
fmt.Println(w.Body.String())
t.Fatalf("unexpected status code: %d", w.Code)
}
w = httptest.NewRecorder()
h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/schema", strings.NewReader("")))
if w.Code != gohttp.StatusOK {
t.Fatalf("unexpected status code: %d", w.Code)
}
rsp := getSchemaResponse{}
if err := json.Unmarshal(w.Body.Bytes(), &rsp); err != nil {
t.Fatalf("json decode: %s", err)
}
field := rsp.findField("i0", fieldName)
if field == nil {
t.Fatalf("field not found: %s", fieldName)
}
if field != nil { // happy linter
if !reflect.DeepEqual(pql.NewDecimal(math.MinInt64, 2), field.Options.Min) {
t.Fatalf("field min %d != %d", pql.NewDecimal(math.MinInt64, 1), field.Options.Min)
}
if !reflect.DeepEqual(pql.NewDecimal(math.MaxInt64, 2), field.Options.Max) {
t.Fatalf("field min %d != %d", pql.NewDecimal(math.MaxInt64, 2), field.Options.Max)
}
}
})
// Ensure that decimal fields error when scale is not provided.
t.Run("Query decimal field scale error", func(t *testing.T) {