From 6c3a5a15613c12187a03b64019e041c5e78a6fb2 Mon Sep 17 00:00:00 2001 From: hulkoba Date: Tue, 18 Nov 2025 13:56:57 +0100 Subject: [PATCH 1/2] test: port 19-find-conflicts from python to elixir --- test/elixir/test/config/suite.elixir | 3 ++ test/elixir/test/mango/19_find_conflicts.exs | 36 ++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 test/elixir/test/mango/19_find_conflicts.exs diff --git a/test/elixir/test/config/suite.elixir b/test/elixir/test/config/suite.elixir index b3fb950846..69b8579749 100644 --- a/test/elixir/test/config/suite.elixir +++ b/test/elixir/test/config/suite.elixir @@ -735,5 +735,8 @@ ], "IgnoreDesignDocsForAllDocsIndexTests": [ "should not return design docs" + ], + "ChooseCorrectIndexForDocs": [ + "retrieve conflicts" ] } diff --git a/test/elixir/test/mango/19_find_conflicts.exs b/test/elixir/test/mango/19_find_conflicts.exs new file mode 100644 index 0000000000..c8fdf41cd7 --- /dev/null +++ b/test/elixir/test/mango/19_find_conflicts.exs @@ -0,0 +1,36 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +defmodule ChooseCorrectIndexForDocs do + use CouchTestCase + + @db_name "find-conflicts" + + setup do + doc = %{"_id" => "doc", "a" => 2} + conflicts = [%{"_id" => "doc", "_rev" => "1-23202479633c2b380f79507a776743d5", "a" => 1}] + + MangoDatabase.recreate(@db_name) + MangoDatabase.save_doc(@db_name, doc) + MangoDatabase.save_docs_with_conflicts(@db_name, conflicts) + :ok + end + + test "retrieve conflicts" do + MangoDatabase.create_index(@db_name, ["_conflicts"]) + selector = %{"_conflicts" => %{"$exists" => true}} + {:ok, result} = MangoDatabase.find(@db_name, selector, conflicts: true) + + assert Enum.at(result, 0)["_conflicts"] == ["1-23202479633c2b380f79507a776743d5"] + assert Enum.at(result, 0)["_rev"] == "1-3975759ccff3842adf690a5c10caee42" + end +end From ad7c3afc089f5e9b297bbe8306c96292ee564b64 Mon Sep 17 00:00:00 2001 From: hulkoba Date: Tue, 18 Nov 2025 13:58:01 +0100 Subject: [PATCH 2/2] test: deprecate 19-find-conflicts.py --- src/mango/test/19-find-conflicts.py | 33 ----------------------------- 1 file changed, 33 deletions(-) delete mode 100644 src/mango/test/19-find-conflicts.py diff --git a/src/mango/test/19-find-conflicts.py b/src/mango/test/19-find-conflicts.py deleted file mode 100644 index e0d2ef3928..0000000000 --- a/src/mango/test/19-find-conflicts.py +++ /dev/null @@ -1,33 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. - -import mango -import copy - -DOC = [{"_id": "doc", "a": 2}] - -CONFLICT = [{"_id": "doc", "_rev": "1-23202479633c2b380f79507a776743d5", "a": 1}] - - -class ChooseCorrectIndexForDocs(mango.DbPerClass): - def setUp(self): - super().setUp(db_per_test=True) - self.db.save_docs(copy.deepcopy(DOC)) - self.db.save_docs_with_conflicts(copy.deepcopy(CONFLICT)) - - def test_retrieve_conflicts(self): - self.db.create_index(["_conflicts"]) - result = self.db.find({"_conflicts": {"$exists": True}}, conflicts=True) - self.assertEqual( - result[0]["_conflicts"][0], "1-23202479633c2b380f79507a776743d5" - ) - self.assertEqual(result[0]["_rev"], "1-3975759ccff3842adf690a5c10caee42")