From 3f2df383ea70dfd9099547c42a2aafc3b09d87d8 Mon Sep 17 00:00:00 2001 From: "Karrick S. McDermott" Date: Mon, 14 Oct 2019 15:59:18 -0400 Subject: [PATCH] empty namespace allowed In accordance with Avro specification: http://avro.apache.org/docs/1.9.1/spec.html#names Resolves: #177 --- name.go | 4 ++-- name_test.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/name.go b/name.go index 935a6c7..2a36726 100644 --- a/name.go +++ b/name.go @@ -121,8 +121,8 @@ func newNameFromSchemaMap(enclosingNamespace string, schemaMap map[string]interf } if namespace, ok := schemaMap["namespace"]; ok { namespaceString, ok = namespace.(string) - if !ok || namespaceString == nullNamespace { - return nil, fmt.Errorf("schema namespace, if provided, ought to be non-empty string; received: %T: %v", namespace, namespace) + if !ok { + return nil, fmt.Errorf("schema namespace, if provided, ought to be a string; received: %T: %v", namespace, namespace) } } diff --git a/name_test.go b/name_test.go index a5ecb09..afb4483 100644 --- a/name_test.go +++ b/name_test.go @@ -82,3 +82,19 @@ func TestNameWithoutDotsButWithEmptyNamespaceAndEnclosingName(t *testing.T) { t.Errorf("GOT: %#v; WANT: %#v", actual, expected) } } + +func TestNewNameFromSchemaMap(t *testing.T) { + n, err := newNameFromSchemaMap(nullNamespace, map[string]interface{}{ + "name": "foo", + "namespace": "", + "type": map[string]interface{}{}, + }) + ensureError(t, err) + + if got, want := n.fullName, "foo"; got != want { + t.Errorf("GOT: %q; WANT: %q", got, want) + } + if got, want := n.namespace, ""; got != want { + t.Errorf("GOT: %q; WANT: %q", got, want) + } +}