mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
default BSI base value to min, max, or 0 depending on the min/max range
This commit is contained in:
parent
a0560a0405
commit
c5140ba88d
2 changed files with 35 additions and 0 deletions
9
field.go
9
field.go
|
|
@ -143,6 +143,15 @@ func OptFieldTypeInt(min, max int64) FieldOption {
|
|||
fo.Type = FieldTypeInt
|
||||
fo.Min = min
|
||||
fo.Max = max
|
||||
// Base is not exposed as a field option argument.
|
||||
// It defaults to min, max, or 0 depending on the min/max range.
|
||||
if min > 0 {
|
||||
fo.Base = min
|
||||
} else if max < 0 {
|
||||
fo.Base = max
|
||||
} else {
|
||||
fo.Base = 0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -412,3 +412,29 @@ func TestField_PersistAvailableShardsFootprint(t *testing.T) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
// Ensure that FieldOptions.Base defaults to the correct value.
|
||||
func TestBSIGroup_BaseDefaultValue(t *testing.T) {
|
||||
for i, tt := range []struct {
|
||||
min int64
|
||||
max int64
|
||||
expBase int64
|
||||
}{
|
||||
{100, 200, 100},
|
||||
{-100, 100, 0},
|
||||
{-200, -100, -100},
|
||||
} {
|
||||
fn := OptFieldTypeInt(tt.min, tt.max)
|
||||
|
||||
// Apply functional option.
|
||||
fo := FieldOptions{}
|
||||
err := fn(&fo)
|
||||
if err != nil {
|
||||
t.Fatalf("test %d, applying functional option: %s", i, err.Error())
|
||||
}
|
||||
|
||||
if fo.Base != tt.expBase {
|
||||
t.Fatalf("test %d, unexpected FieldOptions.Base value. expected: %d, but got: %d", i, tt.expBase, fo.Base)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue