mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
fix cacheSize when cacheType is none (and cacheSize is 0)
There was an edge case where setting cacheType to none wouldn't zero out its cacheSize. This fixes that edge case.
This commit is contained in:
parent
9d7ef20206
commit
4af91faa7e
2 changed files with 36 additions and 6 deletions
10
field.go
10
field.go
|
|
@ -596,12 +596,10 @@ func (f *Field) applyOptions(opt FieldOptions) error {
|
|||
if opt.CacheType != "" {
|
||||
f.options.CacheType = opt.CacheType
|
||||
}
|
||||
if opt.CacheSize != 0 {
|
||||
if opt.CacheType == CacheTypeNone {
|
||||
f.options.CacheSize = 0
|
||||
} else {
|
||||
f.options.CacheSize = opt.CacheSize
|
||||
}
|
||||
if opt.CacheType == CacheTypeNone {
|
||||
f.options.CacheSize = 0
|
||||
} else if opt.CacheSize != 0 {
|
||||
f.options.CacheSize = opt.CacheSize
|
||||
}
|
||||
f.options.Min = 0
|
||||
f.options.Max = 0
|
||||
|
|
|
|||
|
|
@ -438,3 +438,35 @@ func TestBSIGroup_BaseDefaultValue(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestField_ApplyOptions(t *testing.T) {
|
||||
for i, tt := range []struct {
|
||||
opts FieldOptions
|
||||
expOpts FieldOptions
|
||||
}{
|
||||
{
|
||||
FieldOptions{
|
||||
Type: FieldTypeSet,
|
||||
CacheType: CacheTypeNone,
|
||||
CacheSize: 0,
|
||||
},
|
||||
FieldOptions{
|
||||
Type: FieldTypeSet,
|
||||
CacheType: CacheTypeNone,
|
||||
CacheSize: 0,
|
||||
},
|
||||
},
|
||||
} {
|
||||
|
||||
fld := &Field{}
|
||||
fld.options = applyDefaultOptions(FieldOptions{})
|
||||
|
||||
fld.applyOptions(tt.opts)
|
||||
|
||||
if fld.options.CacheType != tt.expOpts.CacheType {
|
||||
t.Fatalf("test %d, unexpected FieldOptions.CacheType value. expected: %s, but got: %s", i, tt.expOpts.CacheType, fld.options.CacheType)
|
||||
} else if fld.options.CacheSize != tt.expOpts.CacheSize {
|
||||
t.Fatalf("test %d, unexpected FieldOptions.CacheSize value. expected: %d, but got: %d", i, tt.expOpts.CacheSize, fld.options.CacheSize)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue