update test

This commit is contained in:
Linh Vo 2017-09-26 13:46:00 -05:00
parent 505363d8ed
commit a1a6c7d717
5 changed files with 33 additions and 30 deletions

View file

@ -441,8 +441,8 @@ func (f *Frame) CreateField(field *Field) error {
// GetFields list all the fields.
func (f *Frame) GetFields() (*FrameSchema, error) {
//f.mu.Lock()
//defer f.mu.Unlock()
f.mu.Lock()
defer f.mu.Unlock()
// Ensure frame supports fields.
if !f.RangeEnabled() {
@ -452,8 +452,6 @@ func (f *Frame) GetFields() (*FrameSchema, error) {
if err != nil {
return nil, err
}
fmt.Println("HERE")
fmt.Printf("%+v\n", f.schema)
return f.schema, nil
}
@ -463,7 +461,7 @@ func (f *Frame) DeleteField(name string) error {
defer f.mu.Unlock()
// Ensure frame supports fields.
if f.rangeEnabled {
if !f.rangeEnabled {
return ErrFrameFieldsNotAllowed
}

View file

@ -842,14 +842,13 @@ func (h *Handler) handleDeleteFrameField(w http.ResponseWriter, r *http.Request)
}
}
func (h *Handler) handleGetFrameField(w http.ResponseWriter, r *http.Request) {
func (h *Handler) handleGetFrameField(w http.ResponseWriter, r *http.Request) {
indexName := mux.Vars(r)["index"]
frameName := mux.Vars(r)["frame"]
index := h.Holder.index(indexName)
frame := index.frame(frameName)
schema, err := frame.GetFields()
fmt.Printf("%+v\n", schema)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return

View file

@ -32,7 +32,6 @@ import (
"github.com/pilosa/pilosa/internal"
"github.com/pilosa/pilosa/pql"
"github.com/pilosa/pilosa/test"
"fmt"
)
func TestHandlerPanics(t *testing.T) {
@ -977,7 +976,6 @@ func TestHandler_Frame_DeleteField(t *testing.T) {
t.Run("OK", func(t *testing.T) {
idx := hldr.MustCreateIndexIfNotExists("i", pilosa.IndexOptions{})
f, err := idx.CreateFrameIfNotExists("f", pilosa.FrameOptions{RangeEnabled: true})
fmt.Println(f.RangeEnabled())
if err != nil {
t.Fatal(err)
} else if err := f.CreateField(&pilosa.Field{Name: "x", Type: pilosa.FieldTypeInt, Min: 0, Max: 100}); err != nil {
@ -1040,36 +1038,40 @@ func TestHandler_Frame_GetFields(t *testing.T) {
s.Handler.Holder = hldr.Holder
defer s.Close()
t.Run("OK", func(t *testing.T) {
idx := hldr.MustCreateIndexIfNotExists("i", pilosa.IndexOptions{})
f, err := idx.CreateFrameIfNotExists("f", pilosa.FrameOptions{RangeEnabled: true})
fmt.Println(f.RangeEnabled())
if err != nil {
t.Fatal(err)
} else if err := f.CreateField(&pilosa.Field{Name: "x", Type: pilosa.FieldTypeInt, Min: 1, Max: 100}); err != nil {
t.Fatal(err)
}
fmt.Println(f.RangeEnabled())
resp, err := http.Get(s.URL+"/index/i/frame/f/fields")
resp, err := http.Get(s.URL + "/index/i/frame/f/fields")
if err != nil {
t.Fatal(err)
}
body, err := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
if err != nil {
t.Fatal(err)
} else if resp.StatusCode != http.StatusOK {
} else if resp.StatusCode != http.StatusOK {
t.Fatalf("unexpected status code: %d", resp.StatusCode)
}
//var fields []pilosa.Field
//if err = json.NewDecoder(resp.Body).Decode(&fields); err != nil {
// t.Fatal(err)
//}
//if fields[0].Name != "x" {
// t.Fatalf("expected field's name: x, actuall name: %v", fields[0].Name)
//}
var fields FrameFields
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
if err = json.Unmarshal([]byte(body), &fields); err != nil {
t.Fatal(err)
}
field := fields.Fields[0]
if field.Name != "x" {
t.Fatalf("expected field's name: x, actuall name: %v", field.Name)
} else if field.Min != 1 {
t.Fatalf("expected field's min: x, actuall min: %v", field.Min)
} else if field.Max != 100 {
t.Fatalf("expected field's max: x, actuall max: %v", field.Max)
}
//
//
//if field := f.Field("x"); field != nil {
@ -1078,6 +1080,11 @@ func TestHandler_Frame_GetFields(t *testing.T) {
})
}
type FrameFields struct {
Fields []pilosa.Field
}
// Ensure the handler can backup a fragment and then restore it.
func TestHandler_Fragment_BackupRestore(t *testing.T) {
hldr := test.MustOpenHolder()

View file

@ -477,7 +477,6 @@ func (i *Index) createFrame(name string, opt FrameOptions) (*Frame, error) {
}
f.rangeEnabled = opt.RangeEnabled
fmt.Println("CREATE FRAME", opt.RangeEnabled)
// Set schema & save.
f.schema = &FrameSchema{

View file

@ -203,14 +203,14 @@ func TestHandleAction(t *testing.T) {
name string
value interface{}
expected uint64
err string
err string
}{
{name: "integer single-row-bool", action: pilosa.InputSingleRowBool, value: 1, err: "single-row-boolean value"},
{name: "string single-row-bool", action: pilosa.InputSingleRowBool,value: "1", err: "single-row-boolean value 1 must equate to a Bool"},
{name: "string value-to-row", action: pilosa.InputValueToRow,value: "25", err: "value-to-row value must equate to an integer"},
{name: "string mapping", action: pilosa.InputMapping,value: "test", err: "Value test does not exist in definition map"},
{name: "int mapping", action: pilosa.InputMapping,value: 25, err: "Mapping value must be a string"},
{name: "invalid action", action: "test",value: true, err: "Unrecognized Value Destination"},
{name: "string single-row-bool", action: pilosa.InputSingleRowBool, value: "1", err: "single-row-boolean value 1 must equate to a Bool"},
{name: "string value-to-row", action: pilosa.InputValueToRow, value: "25", err: "value-to-row value must equate to an integer"},
{name: "string mapping", action: pilosa.InputMapping, value: "test", err: "Value test does not exist in definition map"},
{name: "int mapping", action: pilosa.InputMapping, value: 25, err: "Mapping value must be a string"},
{name: "invalid action", action: "test", value: true, err: "Unrecognized Value Destination"},
}
for _, r := range tests {
t.Run(r.name, func(t *testing.T) {