Skip to content

Commit

Permalink
add unittest for struct and struct-field
Browse files Browse the repository at this point in the history
the values are based on the example for the type map<key-type,value-type> of field https://docs.vespa.ai/en/reference/schema-reference.html#field
  • Loading branch information
maxice8 committed Sep 13, 2024
1 parent 9097d87 commit c6fa567
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/unit/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
ApplicationPackage,
AuthClient,
DeploymentConfiguration,
Struct,
StructField,
)


Expand Down Expand Up @@ -1648,3 +1650,51 @@ def test_deployment_to_text(self):
)

self.assertEqual(expected_result, app_package.deployment_to_text)


class TestSchemaStructField(unittest.TestCase):
def setUp(self):
self.app_package = ApplicationPackage(name="struct")

mystruct = Struct("mystruct", [Field("key", "string"), Field("value", "int")])

my_array = Field(
"my_array",
"array<mystruct>",
["summary"],
struct_fields=[
StructField(
"key",
indexing=["attribute"],
attribute=["fast-search"],
rank="filter",
)
],
)

self.app_package.schema.document = Document([my_array], None, [mystruct])

def test_schema_to_text(self):
expected_result = (
"schema struct {\n"
" document struct {\n"
" field my_array type array<mystruct> {\n"
" indexing: summary\n"
" struct-field key {\n"
" indexing: attribute\n"
" attribute {\n"
" fast-search\n"
" }\n"
" rank: filter\n"
" }\n"
" }\n"
" struct mystruct {\n"
" field key type string {\n"
" }\n"
" field value type int {\n"
" }\n"
" }\n"
" }\n"
"}"
)
self.assertEqual(self.app_package.schema.schema_to_text, expected_result)

0 comments on commit c6fa567

Please sign in to comment.