mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-09 14:41:02 +00:00
Merge pull request #1574 from kuba--/public-name-validator
Make validateName function public,
This commit is contained in:
commit
358e4b860e
6 changed files with 13 additions and 13 deletions
2
field.go
2
field.go
|
|
@ -354,7 +354,7 @@ func OptFieldTypeBool() FieldOption {
|
|||
// this function couldn't be used to set, for example,
|
||||
// `FieldOptions.Keys`.
|
||||
func NewField(holder *Holder, path, index, name string, opts FieldOption) (*Field, error) {
|
||||
err := validateName(name)
|
||||
err := ValidateName(name)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "validating name")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1174,7 +1174,7 @@ func (h *Holder) persistIndex(ctx context.Context, cim *CreateIndexMessage) erro
|
|||
return ErrIndexRequired
|
||||
}
|
||||
|
||||
if err := validateName(cim.Index); err != nil {
|
||||
if err := ValidateName(cim.Index); err != nil {
|
||||
return errors.Wrap(err, "validating name")
|
||||
}
|
||||
|
||||
|
|
|
|||
12
index.go
12
index.go
|
|
@ -82,7 +82,7 @@ func NewIndex(holder *Holder, path, name string) (*Index, error) {
|
|||
// the defaults, because we may be under a simple "go test" run where
|
||||
// not all that command line machinery has been spun up.
|
||||
|
||||
err := validateName(name)
|
||||
err := ValidateName(name)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "validating name")
|
||||
}
|
||||
|
|
@ -554,7 +554,7 @@ func (i *Index) recalculateCaches() {
|
|||
|
||||
// CreateField creates a field.
|
||||
func (i *Index) CreateField(name string, opts ...FieldOption) (*Field, error) {
|
||||
err := validateName(name)
|
||||
err := ValidateName(name)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "validating name")
|
||||
}
|
||||
|
|
@ -592,7 +592,7 @@ func (i *Index) CreateField(name string, opts ...FieldOption) (*Field, error) {
|
|||
// creation to other nodes so they can create locally as well. An error is
|
||||
// returned if the field already exists.
|
||||
func (i *Index) CreateFieldAndBroadcast(cfm *CreateFieldMessage) (*Field, error) {
|
||||
err := validateName(cfm.Field)
|
||||
err := ValidateName(cfm.Field)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "validating name")
|
||||
}
|
||||
|
|
@ -615,7 +615,7 @@ func (i *Index) CreateFieldAndBroadcast(cfm *CreateFieldMessage) (*Field, error)
|
|||
|
||||
// CreateFieldIfNotExists creates a field with the given options if it doesn't exist.
|
||||
func (i *Index) CreateFieldIfNotExists(name string, opts ...FieldOption) (*Field, error) {
|
||||
err := validateName(name)
|
||||
err := ValidateName(name)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "validating name")
|
||||
}
|
||||
|
|
@ -659,7 +659,7 @@ func (i *Index) CreateFieldIfNotExists(name string, opts ...FieldOption) (*Field
|
|||
// definintely be refactored so we don't have these virtually equivalent
|
||||
// methods, but I'm puttin this here for now just to see if it works.
|
||||
func (i *Index) CreateFieldIfNotExistsWithOptions(name string, opt *FieldOptions) (*Field, error) {
|
||||
err := validateName(name)
|
||||
err := ValidateName(name)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "validating name")
|
||||
}
|
||||
|
|
@ -699,7 +699,7 @@ func (i *Index) persistField(ctx context.Context, cfm *CreateFieldMessage) error
|
|||
return ErrFieldRequired
|
||||
}
|
||||
|
||||
if err := validateName(cfm.Field); err != nil {
|
||||
if err := ValidateName(cfm.Field); err != nil {
|
||||
return errors.Wrap(err, "validating name")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -180,8 +180,8 @@ func (cas ColumnAttrSet) MarshalJSON() ([]byte, error) {
|
|||
// TimeFormat is the go-style time format used to parse string dates.
|
||||
const TimeFormat = "2006-01-02T15:04"
|
||||
|
||||
// validateName ensures that the index or field or view name is a valid format.
|
||||
func validateName(name string) error {
|
||||
// ValidateName ensures that the index or field or view name is a valid format.
|
||||
func ValidateName(name string) error {
|
||||
if !nameRegexp.Match([]byte(name)) {
|
||||
return errors.Wrapf(ErrName, "'%s'", name)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ func TestValidateName(t *testing.T) {
|
|||
"longbutnottoolongaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa12345689012345689012345678901234567890",
|
||||
}
|
||||
for _, name := range names {
|
||||
if validateName(name) != nil {
|
||||
if ValidateName(name) != nil {
|
||||
t.Fatalf("Should be valid index name: %s", name)
|
||||
}
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ func TestValidateNameInvalid(t *testing.T) {
|
|||
"long123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1", "_exists",
|
||||
}
|
||||
for _, name := range names {
|
||||
if validateName(name) == nil {
|
||||
if ValidateName(name) == nil {
|
||||
t.Fatalf("Should be invalid index name: %s", name)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
view.go
2
view.go
|
|
@ -70,7 +70,7 @@ type view struct {
|
|||
|
||||
// newView returns a new instance of View.
|
||||
func newView(holder *Holder, path, index, field, name string, fieldOptions FieldOptions) *view {
|
||||
PanicOn(validateName(name))
|
||||
PanicOn(ValidateName(name))
|
||||
|
||||
return &view{
|
||||
path: path,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue