From 9fc308925b210bb3053ed769a30e1f83edb0c5b1 Mon Sep 17 00:00:00 2001 From: Linh Vo Date: Fri, 1 Sep 2017 16:49:04 -0500 Subject: [PATCH] fix rowID=0 bug --- fragment_test.go | 41 +++++++++++++++++------------------ input_definition.go | 3 +-- input_definition_test.go | 46 ++++++++++++++++++++-------------------- 3 files changed, 44 insertions(+), 46 deletions(-) diff --git a/fragment_test.go b/fragment_test.go index 702eec70a..e7f112837 100644 --- a/fragment_test.go +++ b/fragment_test.go @@ -940,28 +940,27 @@ func TestFragment_Zero_Tanimoto(t *testing.T) { } func TestFragment_Snapshot_Run(t *testing.T) { - f := test.MustOpenFragment("i", "f", pilosa.ViewStandard, 0, "") - defer f.Close() + f := test.MustOpenFragment("i", "f", pilosa.ViewStandard, 0, "") + defer f.Close() - // Set bits on the fragment. - for i := uint64(1); i < 3; i++ { - if _, err := f.SetBit(1000, i); err != nil { - t.Fatal(err) - } - } + // Set bits on the fragment. + for i := uint64(1); i < 3; i++ { + if _, err := f.SetBit(1000, i); err != nil { + t.Fatal(err) + } + } - // Snapshot bitmap and verify data. - if err := f.Snapshot(); err != nil { - t.Fatal(err) - } else if n := f.Row(1000).Count(); n != 2 { - t.Fatalf("unexpected count: %d", n) - } + // Snapshot bitmap and verify data. + if err := f.Snapshot(); err != nil { + t.Fatal(err) + } else if n := f.Row(1000).Count(); n != 2 { + t.Fatalf("unexpected count: %d", n) + } - // Close and reopen the fragment & verify the data. - if err := f.Reopen(); err != nil { - t.Fatal(err) - } else if n := f.Row(1000).Count(); n != 2 { - t.Fatalf("unexpected count (reopen): %d", n) - } + // Close and reopen the fragment & verify the data. + if err := f.Reopen(); err != nil { + t.Fatal(err) + } else if n := f.Row(1000).Count(); n != 2 { + t.Fatalf("unexpected count (reopen): %d", n) + } } - diff --git a/input_definition.go b/input_definition.go index ab5af2bc4..faa303eda 100644 --- a/input_definition.go +++ b/input_definition.go @@ -211,7 +211,6 @@ func (a *Action) Validate() error { if len(a.ValueMap) == 0 { return ErrInputDefinitionValueMap } - case InputSetTimestamp: } @@ -372,7 +371,7 @@ func HandleAction(a Action, value interface{}, colID uint64, timestamp int64) (* } bit.RowID = uint64(v) case InputSetTimestamp: - break + return nil, nil default: return nil, fmt.Errorf("Unrecognized Value Destination: %s in Action", a.ValueDestination) } diff --git a/input_definition_test.go b/input_definition_test.go index da6e91231..550549c9a 100644 --- a/input_definition_test.go +++ b/input_definition_test.go @@ -198,34 +198,26 @@ func TestHandleAction(t *testing.T) { action := pilosa.Action{ValueDestination: pilosa.InputSingleRowBool, RowID: &rowID} timestamp := int64(0) - value = 1 - b, err := pilosa.HandleAction(action, value, colID, timestamp) - if b != nil { - t.Fatalf("Expected integer type is not handled by single-row-boolean") - } else if !strings.Contains(err.Error(), "single-row-boolean value") { - t.Fatalf("Expected single-row-boolean value error, actual error: %s", err) + tests := []struct { + name string + value interface{} + expected string + }{ + {name: "integer value", value: 1, expected: "single-row-boolean value"}, + {name: "string value", value: "1", expected: "single-row-boolean value 1 must equate to a Bool"}, } + for _, r := range tests { + t.Run(r.name, func(t *testing.T) { + _, err := pilosa.HandleAction(action, r.value, colID, timestamp) + if !strings.Contains(err.Error(), r.expected) { + t.Fatalf("Expect err: %s, actual: %s", r.expected, err.Error()) + } + }) - value = "1" - b, err = pilosa.HandleAction(action, value, colID, timestamp) - if b != nil { - t.Fatalf("Expected Ignore strings, only accept boolean") - } - - value = "t" - b, err = pilosa.HandleAction(action, value, colID, timestamp) - if !strings.Contains(err.Error(), "must equate to a Bool") { - t.Fatalf("Expected Unrecognized Value Destination error, actual error: %s", err) - } - - value = float64(1) - b, err = pilosa.HandleAction(action, value, colID, timestamp) - if !strings.Contains(err.Error(), "must equate to a Bool") { - t.Fatalf("Expected Unrecognized Value Destination error, actual error: %s", err) } value = false - b, err = pilosa.HandleAction(action, value, colID, timestamp) + b, err := pilosa.HandleAction(action, value, colID, timestamp) if b != nil { t.Fatalf("Expected Ignore values that do not equate to True") } @@ -274,4 +266,12 @@ func TestHandleAction(t *testing.T) { if !strings.Contains(err.Error(), "Unrecognized Value Destination") { t.Fatalf("Expected Unrecognized Value Destination error, actual error: %s", err) } + + action.ValueDestination = pilosa.InputSetTimestamp + t.Run("nil bit", func(t *testing.T) { + b, err = pilosa.HandleAction(action, value, colID, timestamp) + if b != nil { + t.Fatalf("Expected nil bit is set") + } + }) }