From da2b5aa0331cf5ff9d58dd2c972583c93b2e9f02 Mon Sep 17 00:00:00 2001 From: Tor Brede Vekterli Date: Thu, 5 Dec 2024 15:29:54 +0000 Subject: [PATCH] Refactor to reduce code duplication --- tests/search/tensor_feed/tensor_feed.rb | 28 +++++++++++-------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/tests/search/tensor_feed/tensor_feed.rb b/tests/search/tensor_feed/tensor_feed.rb index 543e13e9c..200be8ed9 100644 --- a/tests/search/tensor_feed/tensor_feed.rb +++ b/tests/search/tensor_feed/tensor_feed.rb @@ -21,22 +21,13 @@ def test_tensor_json_feed puts "search_docs: #{search_docs}" assert_tensor_docs(search_docs) - visit_response = vespa.document_api_v1.visit(:selection => "test.my_tensor", :fieldSet => "test:[document]", :cluster => "search", :wantedDocumentCount => 10) - puts "visit_response: #{visit_response}" - visit_docs = extract_visit_docs(visit_response) - puts "visit_docs: #{visit_docs}" + visit_docs = visit_tensor_docs('test.my_tensor') assert_visit_result_tensor_present(visit_docs) - visit_response = vespa.document_api_v1.visit(:selection => "not test.my_tensor", :fieldSet => "test:[document]", :cluster => "search", :wantedDocumentCount => 10) - puts "visit_response: #{visit_response}" - visit_docs = extract_visit_docs(visit_response) - puts "visit_docs: #{visit_docs}" + visit_docs = visit_tensor_docs('not test.my_tensor') assert_visit_result_tensor_not_present(visit_docs) - visit_response = vespa.document_api_v1.visit(:selection => "test", :fieldSet => "test:[document]", :cluster => "search", :wantedDocumentCount => 10) - puts "visit_response: #{visit_response}" - visit_docs = extract_visit_docs(visit_response) - puts "visit_docs: #{visit_docs}" + visit_docs = visit_tensor_docs('test') assert_tensor_docs(visit_docs) feed(:file => @base_dir + "updates.json") @@ -44,10 +35,7 @@ def test_tensor_json_feed puts "search_docs: #{search_docs}" assert_tensor_docs_after_updates(search_docs) - visit_response = vespa.document_api_v1.visit(:selection => "test", :fieldSet => "test:[document]", :cluster => "search", :wantedDocumentCount => 10) - puts "visit_response: #{visit_response}" - visit_docs = extract_visit_docs(visit_response) - puts "visit_docs: #{visit_docs}" + visit_docs = visit_tensor_docs('test') assert_tensor_docs_after_updates(visit_docs) end @@ -98,6 +86,14 @@ def run_tensor_json_feed_attribute assert_tensor_docs_after_updates(search_docs) end + def visit_tensor_docs(selection) + visit_response = vespa.document_api_v1.visit(:selection => selection, :fieldSet => "test:[document]", :cluster => "search", :wantedDocumentCount => 10) + puts "visit_response: #{visit_response}" + visit_docs = extract_visit_docs(visit_response) + puts "visit_docs: #{visit_docs}" + visit_docs + end + def extract_doc_ids(docs) docs.map { |d| d['id'] }.to_a end