mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 00:55:55 +00:00
FB-1188 - Fixed units tests for TTL
This commit is contained in:
parent
e16171cb4b
commit
883e940d7f
4 changed files with 21 additions and 28 deletions
|
|
@ -1674,18 +1674,18 @@ type SchemaField struct {
|
|||
|
||||
// SchemaOptions contains options for a field or an index.
|
||||
type SchemaOptions struct {
|
||||
FieldType FieldType `json:"type"`
|
||||
CacheType string `json:"cacheType"`
|
||||
CacheSize uint `json:"cacheSize"`
|
||||
TimeQuantum string `json:"timeQuantum"`
|
||||
Ttl string `json:"ttl"`
|
||||
Min pql.Decimal `json:"min"`
|
||||
Max pql.Decimal `json:"max"`
|
||||
Scale int64 `json:"scale"`
|
||||
Keys bool `json:"keys"`
|
||||
NoStandardView bool `json:"noStandardView"`
|
||||
TrackExistence bool `json:"trackExistence"`
|
||||
TimeUnit string `json:"timeUnit"`
|
||||
FieldType FieldType `json:"type"`
|
||||
CacheType string `json:"cacheType"`
|
||||
CacheSize uint `json:"cacheSize"`
|
||||
TimeQuantum string `json:"timeQuantum"`
|
||||
Ttl time.Duration `json:"ttl"`
|
||||
Min pql.Decimal `json:"min"`
|
||||
Max pql.Decimal `json:"max"`
|
||||
Scale int64 `json:"scale"`
|
||||
Keys bool `json:"keys"`
|
||||
NoStandardView bool `json:"noStandardView"`
|
||||
TrackExistence bool `json:"trackExistence"`
|
||||
TimeUnit string `json:"timeUnit"`
|
||||
}
|
||||
|
||||
func (so SchemaOptions) asIndexOptions() *IndexOptions {
|
||||
|
|
@ -1698,25 +1698,12 @@ func (so SchemaOptions) asIndexOptions() *IndexOptions {
|
|||
}
|
||||
|
||||
func (so SchemaOptions) asFieldOptions() *FieldOptions {
|
||||
var ttlValue time.Duration
|
||||
if so.Ttl != "" {
|
||||
ttlVal, err := time.ParseDuration(so.Ttl)
|
||||
if err != nil {
|
||||
ttlValue = 0
|
||||
fmt.Println(fmt.Errorf("ParseDuration error: %v", err))
|
||||
} else {
|
||||
ttlValue = ttlVal
|
||||
}
|
||||
} else {
|
||||
ttlValue = 0
|
||||
}
|
||||
|
||||
return &FieldOptions{
|
||||
fieldType: so.FieldType,
|
||||
cacheSize: int(so.CacheSize),
|
||||
cacheType: CacheType(so.CacheType),
|
||||
timeQuantum: TimeQuantum(so.TimeQuantum),
|
||||
ttl: ttlValue,
|
||||
ttl: so.Ttl,
|
||||
min: so.Min,
|
||||
max: so.Max,
|
||||
scale: so.Scale,
|
||||
|
|
|
|||
|
|
@ -1004,7 +1004,7 @@ func TestORM(t *testing.T) {
|
|||
t.Fatalf("field noStandardView %v != %v", true, field.Opts().NoStandardView())
|
||||
}
|
||||
jsonString := field.options.String()
|
||||
targetString := `{"options":{"noStandardView":true,"type":"time","timeQuantum":"DH"}}`
|
||||
targetString := `{"options":{"noStandardView":true,"type":"time","timeQuantum":"DH","ttl":"0s"}}`
|
||||
if sortedString(targetString) != sortedString(jsonString) {
|
||||
t.Fatalf("`%s` != `%s`", targetString, jsonString)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1615,7 +1615,11 @@ func fieldOptionsToFunctionalOpts(opt fieldOptions) []FieldOption {
|
|||
}
|
||||
fos = append(fos, OptFieldTypeTimestamp(opt.Epoch.UTC(), *opt.TimeUnit))
|
||||
case FieldTypeTime:
|
||||
fos = append(fos, OptFieldTypeTime(*opt.TimeQuantum, *opt.Ttl, opt.NoStandardView))
|
||||
if opt.Ttl != nil {
|
||||
fos = append(fos, OptFieldTypeTime(*opt.TimeQuantum, *opt.Ttl, opt.NoStandardView))
|
||||
} else {
|
||||
fos = append(fos, OptFieldTypeTime(*opt.TimeQuantum, "0", opt.NoStandardView))
|
||||
}
|
||||
case FieldTypeMutex:
|
||||
fos = append(fos, OptFieldTypeMutex(*opt.CacheType, *opt.CacheSize))
|
||||
case FieldTypeBool:
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@ func TestFieldOptionValidation(t *testing.T) {
|
|||
{json: `{"options": {"type": "set", "min": 0}}`, err: "min does not apply to field type set"},
|
||||
{json: `{"options": {"type": "set", "max": 100}}`, err: "max does not apply to field type set"},
|
||||
{json: `{"options": {"type": "set", "timeQuantum": "YMD"}}`, err: "timeQuantum does not apply to field type set"},
|
||||
{json: `{"options": {"type": "set", "ttl": "1h"}}`, err: "ttl does not apply to field type set"},
|
||||
|
||||
// FieldType: Int
|
||||
{json: `{"options": {"type": "int"}}`, err: "min is required for field type int"},
|
||||
|
|
@ -143,6 +144,7 @@ func TestFieldOptionValidation(t *testing.T) {
|
|||
{json: `{"options": {"type": "int", "min": 0, "max": 1000, "cacheType": "ranked"}}`, err: "cacheType does not apply to field type int"},
|
||||
{json: `{"options": {"type": "int", "min": 0, "max": 1000, "cacheSize": 1000}}`, err: "cacheSize does not apply to field type int"},
|
||||
{json: `{"options": {"type": "int", "min": 0, "max": 1000, "timeQuantum": "YMD"}}`, err: "timeQuantum does not apply to field type int"},
|
||||
{json: `{"options": {"type": "int", "min": 0, "max": 1000, "ttl": "1h"}}`, err: "ttl does not apply to field type int"},
|
||||
|
||||
// FieldType: Time
|
||||
{json: `{"options": {"type": "time"}}`, err: "timeQuantum is required for field type time"},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue