Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only validate name, not all components #96

Merged
merged 1 commit into from
Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions name.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ func newName(n, ns, ens string) (*name, error) {
nn.namespace = n[:index]
} else {
// inputName does not contain a dot, therefore is not the full name
err := checkNameComponent(n)
if err != nil {
return nil, err
}

if ns != nullNamespace {
// if namespace provided in the schema in the same schema level, use it
nn.fullName = ns + "." + n
Expand All @@ -89,13 +94,6 @@ func newName(n, ns, ens string) (*name, error) {
}
}

// verify all components of the full name for adherence to Avro naming rules
for _, component := range strings.Split(nn.fullName, ".") {
if err := checkNameComponent(component); err != nil {
return nil, err
}
}

return &nn, nil
}

Expand Down
15 changes: 14 additions & 1 deletion name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,25 @@ func TestNameStartsInvalidCharacter(t *testing.T) {
}

func TestNameContainsInvalidCharacter(t *testing.T) {
_, err := newName("X", "org.foo&bar", nullNamespace)
_, err := newName("X&", "org.foo.bar", nullNamespace)
if _, ok := err.(ErrInvalidName); err == nil && !ok {
t.Errorf("Actual: %#v, Expected: %#v", err, ErrInvalidName{"start with [A-Za-z_]"})
}
}

func TestNamespaceContainsInvalidCharacter(t *testing.T) {
n, err := newName("X", ".org.foo", nullNamespace)
if err != nil {
t.Fatal(err)
}
if actual, expected := n.fullName, ".org.foo.X"; actual != expected {
t.Errorf("Actual: %#v; Expected: %#v", actual, expected)
}
if actual, expected := n.namespace, ".org.foo"; actual != expected {
t.Errorf("Actual: %#v; Expected: %#v", actual, expected)
}
}

func TestNameAndNamespaceProvided(t *testing.T) {
n, err := newName("X", "org.foo", nullNamespace)
if err != nil {
Expand Down