This is an automated email from the ASF dual-hosted git repository. iilyak pushed a commit to branch add-assert-messages-to-search-elixir-tests in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit e005bbe4b8b01668f0d37bf9db1910f4a9ef6444 Author: ILYA Khlopotov <[email protected]> AuthorDate: Tue Oct 7 12:54:21 2025 -0700 Add assert comments to search related elixir tests --- test/elixir/test/partition_search_test.exs | 77 ++++++++++++++++++------ test/elixir/test/search_test.exs | 97 ++++++++++++++++++++++++------ 2 files changed, 136 insertions(+), 38 deletions(-) diff --git a/test/elixir/test/partition_search_test.exs b/test/elixir/test/partition_search_test.exs index 121995449..18253a9c2 100644 --- a/test/elixir/test/partition_search_test.exs +++ b/test/elixir/test/partition_search_test.exs @@ -22,7 +22,9 @@ defmodule PartitionSearchTest do end resp = Couch.post("/#{db_name}/_bulk_docs", headers: ["Content-Type": "application/json"], body: %{:docs => docs}, query: %{w: 3}) - assert resp.status_code in [201, 202] + assert resp.status_code in [201, 202], + "Cannot create search docs. " <> + "Expected one of [201, 202], got: #{resp.status_code}, body: #{inspect resp.body}" end def create_ddoc(db_name, opts \\ %{}) do @@ -39,7 +41,9 @@ defmodule PartitionSearchTest do ddoc = Enum.into(opts, default_ddoc) resp = Couch.put("/#{db_name}/_design/library", body: ddoc) - assert resp.status_code in [201, 202] + assert resp.status_code in [201, 202], + "Cannot create design doc. " <> + "Expected one of [201, 202], got: #{resp.status_code}, body: #{inspect resp.body}" assert Map.has_key?(resp.body, "ok") == true end @@ -56,13 +60,17 @@ defmodule PartitionSearchTest do url = "/#{db_name}/_partition/foo/_design/library/_search/books" resp = Couch.get(url, query: %{q: "some:field"}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do partition search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" ids = get_ids(resp) assert ids == ["foo:10", "foo:2", "foo:4", "foo:6", "foo:8"] url = "/#{db_name}/_partition/bar/_design/library/_search/books" resp = Couch.get(url, query: %{q: "some:field"}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do partition search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" ids = get_ids(resp) assert ids == ["bar:1", "bar:3", "bar:5", "bar:7", "bar:9"] end @@ -75,7 +83,9 @@ defmodule PartitionSearchTest do url = "/#{db_name}/_partition/foo/_design/library/_search/books" resp = Couch.get(url, query: %{q: "some:field"}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do partition search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" ids = get_ids(resp) assert ids == ["foo:10", "foo:2", "foo:4", "foo:6", "foo:8"] end @@ -88,24 +98,32 @@ defmodule PartitionSearchTest do url = "/#{db_name}/_partition/foo/_design/library/_search/books" resp = Couch.get(url, query: %{q: "some:field", limit: 3}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do partition search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" ids = get_ids(resp) assert ids == ["foo:10", "foo:2", "foo:4"] %{:body => %{"bookmark" => bookmark}} = resp resp = Couch.get(url, query: %{q: "some:field", limit: 3, bookmark: bookmark}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do partition search with a bookmark. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" ids = get_ids(resp) assert ids == ["foo:6", "foo:8"] resp = Couch.get(url, query: %{q: "some:field", limit: 2000, bookmark: bookmark}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do partition search with an upper bound on the limit. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" ids = get_ids(resp) assert ids == ["foo:6", "foo:8"] resp = Couch.get(url, query: %{q: "some:field", limit: 2001, bookmark: bookmark}) - assert resp.status_code == 400 + assert resp.status_code == 400, + "Should fail to do partition search with over limit. " <> + "Expected 400, got: #{resp.status_code}, body: #{inspect resp.body}" end @tag :with_db @@ -116,7 +134,9 @@ defmodule PartitionSearchTest do url = "/#{db_name}/_design/library/_search/books" resp = Couch.post(url, body: %{:q => "some:field", :limit => 1}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do POST for non-partitioned db with limit. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" end @tag :with_partitioned_db @@ -127,7 +147,9 @@ defmodule PartitionSearchTest do url = "/#{db_name}/_partition/foo/_design/library/_search/books" resp = Couch.post(url, body: %{:q => "some:field", :limit => 1}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do POST for partitioned db with limit. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" end @tag :with_partitioned_db @@ -138,7 +160,9 @@ defmodule PartitionSearchTest do url = "/#{db_name}/_design/library/_search/books" resp = Couch.get(url, query: %{q: "some:field"}) - assert resp.status_code == 400 + assert resp.status_code == 400, + "Expected a failure to do a global query on partitioned view. " <> + "Expected 400, got: #{resp.status_code}, body: #{inspect resp.body}" %{:body => %{"reason" => reason}} = resp assert Regex.match?(~r/mandatory for queries to this index./, reason) end @@ -151,7 +175,10 @@ defmodule PartitionSearchTest do url = "/#{db_name}/_partition/foo/_design/library/_search/books" resp = Couch.get(url, query: %{q: "some:field"}) - assert resp.status_code == 400 + assert resp.status_code == 400, + "Expected a failure to do a query with a global search ddoc. " <> + "Expected 400, got: #{resp.status_code}, body: #{inspect resp.body}" + %{:body => %{"reason" => reason}} = resp assert reason == "`partition` not supported on this index" end @@ -164,7 +191,10 @@ defmodule PartitionSearchTest do url = "/#{db_name}/_design/library/_search/books" resp = Couch.get(url, query: %{q: "some:field"}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Failed to search on non-partitioned dbs. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" + ids = get_ids(resp) assert Enum.sort(ids) == Enum.sort(["bar:1", "bar:5", "bar:9", "foo:2", "bar:3", "foo:4", "foo:6", "bar:7", "foo:8", "foo:10"]) end @@ -177,7 +207,10 @@ defmodule PartitionSearchTest do url = "/#{db_name}/_design/library/_search/books" resp = Couch.get(url, query: %{q: "some:field"}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Failed to search on non-partitioned dbs without the limit. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" + ids = get_ids(resp) assert Enum.sort(ids) == Enum.sort(["bar:1", "bar:5", "bar:9", "foo:2", "bar:3", "foo:4", "foo:6", "bar:7", "foo:8", "foo:10"]) end @@ -190,7 +223,10 @@ defmodule PartitionSearchTest do url = "/#{db_name}/_design/library/_search/books" resp = Couch.get(url, query: %{q: "some:field", limit: 3}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Failed to search on non-partitioned dbs with the limit. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" + ids = get_ids(resp) assert Enum.sort(ids) == Enum.sort(["bar:1", "bar:5", "bar:9"]) end @@ -203,7 +239,10 @@ defmodule PartitionSearchTest do url = "/#{db_name}/_design/library/_search/books" resp = Couch.get(url, query: %{q: "some:field", limit: 201}) - assert resp.status_code == 400 + assert resp.status_code == 400, + "Expected a failure on non-partitioned dbs with over limit. " <> + "Expected 400, got: #{resp.status_code}, body: #{inspect resp.body}" + end @tag :with_partitioned_db @@ -214,7 +253,9 @@ defmodule PartitionSearchTest do url = "/#{db_name}/_partition/foo/_design/library/_search/books" resp = Couch.post(url, body: %{q: "some:field", partition: "bar"}) - assert resp.status_code == 400 + assert resp.status_code == 400, + "Expected a failure on conflicting partition values. " <> + "Expected 400, got: #{resp.status_code}, body: #{inspect resp.body}" end @tag :with_partitioned_db diff --git a/test/elixir/test/search_test.exs b/test/elixir/test/search_test.exs index 035e61b5f..16a18652b 100644 --- a/test/elixir/test/search_test.exs +++ b/test/elixir/test/search_test.exs @@ -17,7 +17,10 @@ defmodule SearchTest do %{"item" => "date", "place" => "lobby", "state" => "unknown", "price" => 1.25}, ]} ) - assert resp.status_code in [201, 202] + assert resp.status_code in [201, 202], + "Cannot create search docs. " <> + "Expected one of [201, 202], got: #{resp.status_code}, body: #{inspect resp.body}" + end def create_ddoc(db_name, opts \\ %{}) do @@ -40,7 +43,10 @@ defmodule SearchTest do ddoc = Enum.into(opts, default_ddoc) resp = Couch.put("/#{db_name}/_design/inventory", body: ddoc) - assert resp.status_code in [201, 202] + assert resp.status_code in [201, 202], + "Cannot create design doc. " <> + "Expected one of [201, 202], got: #{resp.status_code}, body: #{inspect resp.body}" + assert Map.has_key?(resp.body, "ok") == true end @@ -54,7 +60,10 @@ defmodule SearchTest do ddoc = Enum.into(opts, invalid_ddoc) resp = Couch.put("/#{db_name}/_design/search", body: ddoc) - assert resp.status_code in [201, 202] + assert resp.status_code in [201, 202], + "Cannot create design doc. " <> + "Expected one of [201, 202], got: #{resp.status_code}, body: #{inspect resp.body}" + assert Map.has_key?(resp.body, "ok") == true end @@ -71,7 +80,10 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits" resp = Couch.get(url, query: %{q: "*:*", include_docs: true}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" + ids = get_items(resp) assert Enum.sort(ids) == Enum.sort(["apple", "banana", "carrot", "date"]) end @@ -84,7 +96,10 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits" resp = Couch.get(url, query: %{q: "*:*", drilldown: :jiffy.encode(["place", "kitchen"]), include_docs: true}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" + ids = get_items(resp) assert Enum.sort(ids) == Enum.sort(["apple", "banana", "carrot"]) end @@ -97,7 +112,10 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits" resp = Couch.get(url, query: %{q: "*:*", drilldown: :jiffy.encode(["state", "new", "unknown"]), include_docs: true}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" + ids = get_items(resp) assert Enum.sort(ids) == Enum.sort(["apple", "banana", "date"]) end @@ -110,7 +128,10 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits" resp = Couch.get(url, query: %{q: "*:*", drilldown: :jiffy.encode([["state", "old"], ["item", "apple"]]), include_docs: true}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" + ids = get_items(resp) assert Enum.sort(ids) == [] end @@ -123,7 +144,10 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits?q=*:*&drilldown=[\"state\",\"old\"]&drilldown=[\"item\",\"apple\"]&include_docs=true" resp = Couch.get(url) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" + ids = get_items(resp) assert Enum.sort(ids) == [] end @@ -137,7 +161,10 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits" resp = Couch.post(url, body: %{q: "*:*", include_docs: true}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" + ids = get_items(resp) assert Enum.sort(ids) == Enum.sort(["apple", "banana", "carrot", "date"]) end @@ -150,7 +177,10 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits" resp = Couch.post(url, body: %{query: "*:*", drilldown: ["place", "kitchen"], include_docs: true}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" + ids = get_items(resp) assert Enum.sort(ids) == Enum.sort(["apple", "banana", "carrot"]) end @@ -163,7 +193,10 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits" resp = Couch.post(url, body: %{query: "*:*", drilldown: ["state", "new", "unknown"], include_docs: true}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" + ids = get_items(resp) assert Enum.sort(ids) == Enum.sort(["apple", "banana", "date"]) end @@ -176,7 +209,10 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits" resp = Couch.post(url, body: %{q: "*:*", drilldown: [["state", "old"], ["item", "apple"]], include_docs: true}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" + ids = get_items(resp) assert Enum.sort(ids) == [] end @@ -189,7 +225,10 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits" resp = Couch.post(url, body: %{q: "*:*", drilldown: [["place", "kitchen"], ["state", "new"], ["item", "apple"]], include_docs: true}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" + ids = get_items(resp) assert Enum.sort(ids) == ["apple"] end @@ -202,7 +241,10 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits" resp = Couch.post(url, body: %{q: "*:*", drilldown: [["state", "old", "new"], ["item", "apple"]], include_docs: true}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" + ids = get_items(resp) assert Enum.sort(ids) == ["apple"] end @@ -215,7 +257,10 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits" resp = Couch.post(url, body: "{\"include_docs\": true, \"q\": \"*:*\", \"drilldown\": [\"state\", \"old\"], \"drilldown\": [\"item\", \"apple\"]}") - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" + ids = get_items(resp) assert Enum.sort(ids) == ["apple"] end @@ -228,7 +273,10 @@ defmodule SearchTest do create_invalid_ddoc(db_name) resp = Couch.post("/#{db_name}/_search_cleanup") - assert resp.status_code in [201, 202] + assert resp.status_code in [201, 202], + "Fail to do a _search_cleanup. " <> + "Expected one of [201, 202], got: #{resp.status_code}, body: #{inspect resp.body}" + end @tag :with_db @@ -240,7 +288,10 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits" counts = ["place"] resp = Couch.get(url, query: %{q: "*:*", limit: 0, counts: :jiffy.encode(counts)}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" + %{:body => %{"counts" => counts}} = resp assert counts == %{"place" => %{"kitchen" => 3, "lobby" => 1}} @@ -255,7 +306,9 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits" counts = ["place"] resp = Couch.get(url, query: %{q: "item:tomato", limit: 0, counts: :jiffy.encode(counts)}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" %{:body => %{"counts" => counts}} = resp assert counts == %{"place" => %{}} @@ -270,7 +323,9 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits" ranges = %{"price" => %{"cheap" => "[0 TO 0.99]", "expensive" => "[1.00 TO Infinity]"}} resp = Couch.get(url, query: %{q: "*:*", limit: 0, ranges: :jiffy.encode(ranges)}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" %{:body => %{"ranges" => ranges}} = resp assert ranges == %{"price" => %{"cheap" => 2, "expensive" => 2}} @@ -285,7 +340,9 @@ defmodule SearchTest do url = "/#{db_name}/_design/inventory/_search/fruits" ranges = %{"price" => %{}} resp = Couch.get(url, query: %{q: "*:*", limit: 0, ranges: :jiffy.encode(ranges)}) - assert resp.status_code == 200 + assert resp.status_code == 200, + "Fail to do search. " <> + "Expected 200, got: #{resp.status_code}, body: #{inspect resp.body}" %{:body => %{"ranges" => ranges}} = resp assert ranges == %{"price" => %{}}
