Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ ifneq ($(_WITH_CLOUSEAU), )
"$(_WITH_CLOUSEAU)" \
"$(TEST_OPTS)" \
--locald-config test/config/test-config.ini \
--no-eval 'mix test --trace --include test/elixir/test/config/search.elixir'
--no-eval 'mix test --trace --include test/elixir/test/config/search.elixir $(EXUNIT_OPTS)'
else
@echo "Warning: Clouseau is not enabled, \`elixir-search\` cannot be run."
endif
Expand Down
69 changes: 0 additions & 69 deletions src/mango/test/17-multi-type-value-test.py

This file was deleted.

4 changes: 2 additions & 2 deletions test/elixir/lib/couch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ defmodule Couch do

def process_request_body(body) do
if is_map(body) do
:jiffy.encode(body)
:jiffy.encode(body, [:use_nil])
else
body
end
Expand All @@ -131,7 +131,7 @@ defmodule Couch do
content_type = headers[:"Content-Type"]

if !!content_type and String.match?(content_type, ~r/application\/json/) do
body |> IO.iodata_to_binary() |> :jiffy.decode([:return_maps])
body |> IO.iodata_to_binary() |> :jiffy.decode([:return_maps, :use_nil])
else
process_response_body(body)
end
Expand Down
8 changes: 4 additions & 4 deletions test/elixir/lib/couch/dbtest.ex
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ defmodule Couch.DBTest do
if prev_value != "" do
url = "/_node/#{node}/_config/#{section}/#{key}"
headers = ["X-Couch-Persist": "false"]
body = :jiffy.encode(prev_value)
body = :jiffy.encode(prev_value, [:use_nil])
resp = Couch.put(url, headers: headers, body: body)
assert resp.status_code == 200
else
Expand All @@ -109,7 +109,7 @@ defmodule Couch.DBTest do
Enum.map(resp.body["all_nodes"], fn node ->
url = "/_node/#{node}/_config/#{section}/#{key}"
headers = ["X-Couch-Persist": "false"]
body = :jiffy.encode(value)
body = :jiffy.encode(value, [:use_nil])
resp = Couch.put(url, headers: headers, body: body)
assert resp.status_code == 200
{node, resp.body}
Expand Down Expand Up @@ -494,7 +494,7 @@ defmodule Couch.DBTest do
Couch.put(
"/_node/#{node}/_config/#{setting.section}/#{setting.key}",
headers: ["X-Couch-Persist": false],
body: :jiffy.encode(setting.value)
body: :jiffy.encode(setting.value, [:use_nil])
)

assert resp.status_code == 200
Expand Down Expand Up @@ -525,7 +525,7 @@ defmodule Couch.DBTest do
Couch.put(
"/_node/#{node}/_config/#{setting.section}/#{setting.key}",
headers: ["X-Couch-Persist": false],
body: :jiffy.encode(value)
body: :jiffy.encode(value, [:use_nil])
)

assert resp.status_code == 200
Expand Down
2 changes: 1 addition & 1 deletion test/elixir/lib/couch_raw.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ defmodule Rawresp do

def process_request_body(body) do
if is_map(body) do
:jiffy.encode(body)
:jiffy.encode(body, [:use_nil])
else
body
end
Expand Down
2 changes: 1 addition & 1 deletion test/elixir/test/all_docs_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ defmodule AllDocsTest do
assert row["key"] == "1"
assert row["id"] == "1"
assert row["value"]["deleted"]
assert row["doc"] == :null
assert row["doc"] == nil

# Add conflicts
conflicted_doc1 = %{
Expand Down
14 changes: 7 additions & 7 deletions test/elixir/test/attachments_multipart_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ defmodule AttachmentMultipartTest do
assert Enum.at(sections, 2).headers["Content-Disposition"] ==
~s(attachment; filename="bar.txt")

doc = :jiffy.decode(Enum.at(sections, 0).body, [:return_maps])
doc = :jiffy.decode(Enum.at(sections, 0).body, [:return_maps, :use_nil])

assert doc["_attachments"]["foo.txt"]["follows"] == true
assert doc["_attachments"]["bar.txt"]["follows"] == true
Expand All @@ -175,7 +175,7 @@ defmodule AttachmentMultipartTest do
sections = parse_multipart(resp)
assert length(sections) == 2

doc = :jiffy.decode(Enum.at(sections, 0).body, [:return_maps])
doc = :jiffy.decode(Enum.at(sections, 0).body, [:return_maps, :use_nil])

assert doc["_attachments"]["foo.txt"]["stub"] == true
assert doc["_attachments"]["bar.txt"]["follows"] == true
Expand Down Expand Up @@ -206,7 +206,7 @@ defmodule AttachmentMultipartTest do
assert length(inner_sections) == 2
assert Enum.at(inner_sections, 0).headers["Content-Type"] == "application/json"

doc = :jiffy.decode(Enum.at(inner_sections, 0).body, [:return_maps])
doc = :jiffy.decode(Enum.at(inner_sections, 0).body, [:return_maps, :use_nil])
assert doc["_attachments"]["foo.txt"]["stub"] == true
assert doc["_attachments"]["bar.txt"]["follows"] == true

Expand All @@ -228,7 +228,7 @@ defmodule AttachmentMultipartTest do

assert length(sections) == 2

doc = :jiffy.decode(Enum.at(sections, 0).body, [:return_maps])
doc = :jiffy.decode(Enum.at(sections, 0).body, [:return_maps, :use_nil])
assert doc["_attachments"]["foo.txt"]["stub"] == true
assert doc["_attachments"]["bar.txt"]["follows"] == true
assert Enum.at(sections, 1).body == "this is 18 chars l"
Expand Down Expand Up @@ -377,7 +377,7 @@ defmodule AttachmentMultipartTest do
assert length(inner_sections) == 3
assert Enum.at(inner_sections, 0).headers["Content-Type"] == "application/json"

doc = :jiffy.decode(Enum.at(inner_sections, 0).body, [:return_maps])
doc = :jiffy.decode(Enum.at(inner_sections, 0).body, [:return_maps, :use_nil])
assert doc["_attachments"]["lorem.txt"]["follows"] == true
assert doc["_attachments"]["lorem.txt"]["encoding"] == "gzip"
assert doc["_attachments"]["data.bin"]["follows"] == true
Expand Down Expand Up @@ -414,7 +414,7 @@ defmodule AttachmentMultipartTest do
# 2 inner sections: a document body section plus 1 attachment data section
assert length(inner_sections) == 2
assert Enum.at(inner_sections, 0).headers["Content-Type"] == "application/json"
doc = :jiffy.decode(Enum.at(inner_sections, 0).body, [:return_maps])
doc = :jiffy.decode(Enum.at(inner_sections, 0).body, [:return_maps, :use_nil])
assert doc["_attachments"]["lorem.txt"]["follows"] == true
assert doc["_attachments"]["lorem.txt"]["encoding"] == "gzip"
assert Enum.at(inner_sections, 1).body != lorem
Expand All @@ -434,7 +434,7 @@ defmodule AttachmentMultipartTest do
boundary = Enum.at(String.split(boundary_arg, "="), 1)

if String.starts_with?(boundary, ~s(")) do
:jiffy.decode(boundary)
:jiffy.decode(boundary, [:use_nil])
else
boundary
end
Expand Down
6 changes: 3 additions & 3 deletions test/elixir/test/changes_async_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ defmodule ChangesAsyncTest do
end

defp parse_chunk(msg) do
msg.chunk |> IO.iodata_to_binary() |> :jiffy.decode([:return_maps])
msg.chunk |> IO.iodata_to_binary() |> :jiffy.decode([:return_maps, :use_nil])
end

defp parse_event(msg) do
Expand All @@ -419,7 +419,7 @@ defmodule ChangesAsyncTest do
|> Enum.map(fn p ->
p
|> IO.iodata_to_binary()
|> :jiffy.decode([:return_maps])
|> :jiffy.decode([:return_maps, :use_nil])
end)
end

Expand Down Expand Up @@ -497,7 +497,7 @@ defmodule ChangesAsyncTest do
body_lines
|> Enum.filter(fn line -> line != "" end)
|> Enum.map(fn line ->
line |> IO.iodata_to_binary() |> :jiffy.decode([:return_maps])
line |> IO.iodata_to_binary() |> :jiffy.decode([:return_maps, :use_nil])
end)
end

Expand Down
2 changes: 1 addition & 1 deletion test/elixir/test/changes_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ defmodule ChangesTest do
assert Enum.member?(changes_ids, "doc1")
assert Enum.member?(changes_ids, "doc3")

encoded_doc_ids = doc_ids.doc_ids |> :jiffy.encode()
encoded_doc_ids = doc_ids.doc_ids |> :jiffy.encode([:use_nil])

resp =
Couch.get("/#{db_name}/_changes",
Expand Down
6 changes: 6 additions & 0 deletions test/elixir/test/config/search.elixir
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,11 @@
"facet counts, empty",
"facet ranges, empty",
"facet ranges, non-empty"
],
"ElemMatchTests": [
"elem match non object"
],
"LimitTests": [
"limit field"
]
}
18 changes: 18 additions & 0 deletions test/elixir/test/config/suite.elixir
Original file line number Diff line number Diff line change
Expand Up @@ -728,5 +728,23 @@
"Creating-Updating/Deleting doc with overriden quorum should return 201-Created/200-OK",
"Creating/Deleting DB should return 202-Acepted",
"Creating/Updating/Deleting doc should return 202-Acepted"
],
"BasicFindTest": [
"simple find"
],
"IgnoreDesignDocsForAllDocsIndexTests": [
"should not return design docs"
],
"MultiValueFieldJSONTests": [
"can query with name",
"can query with name subfield",
"can query with name range",
"can query with age and name range"
],
"MultiValueFieldAllDocsTests": [
"can query with name",
"can query with name subfield",
"can query with name range",
"can query with age and name range"
]
}
2 changes: 1 addition & 1 deletion test/elixir/test/config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule ConfigTest do
def set_config(context, section, key, val, status_assert) do
url = "#{context[:config_url]}/#{section}/#{key}"
headers = ["X-Couch-Persist": "false"]
resp = Couch.put(url, headers: headers, body: :jiffy.encode(val))
resp = Couch.put(url, headers: headers, body: :jiffy.encode(val, [:use_nil]))

if status_assert do
assert resp.status_code == status_assert
Expand Down
2 changes: 1 addition & 1 deletion test/elixir/test/design_docs_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ defmodule DesignDocsTest do
result =
resp.body
|> IO.iodata_to_binary()
|> :jiffy.decode([:return_maps])
|> :jiffy.decode([:return_maps, :use_nil])

assert result["language"] == "javascript"
end
Expand Down
2 changes: 1 addition & 1 deletion test/elixir/test/design_options_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ defmodule DesignOptionsTest do

row_with_key =
resp.body["rows"]
|> Enum.filter(fn p -> p["key"] != :null end)
|> Enum.filter(fn p -> p["key"] != nil end)

assert length(row_with_key) == 2
end
Expand Down
2 changes: 1 addition & 1 deletion test/elixir/test/erlang_views_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ defmodule ErlangViewsTest do
"erlang"
)

assert Map.get(List.first(results["rows"]), "key", :null) == :null
assert Map.get(List.first(results["rows"]), "key", nil) == nil
assert List.first(results["rows"])["value"] > 0
end

Expand Down
2 changes: 1 addition & 1 deletion test/elixir/test/jsonp_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ defmodule JsonpTest do
|> Enum.map(fn p ->
p
|> IO.iodata_to_binary()
|> :jiffy.decode([:return_maps])
|> :jiffy.decode([:return_maps, :use_nil])
end)
|> Enum.at(0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@
# License for the specific language governing permissions and limitations under
# the License.

import mango
import unittest
defmodule BasicFindTest do
use CouchTestCase

DOCS = [
{"_id": "_design/my-design-doc"},
{"_id": "54af50626de419f5109c962f", "user_id": 0, "age": 10, "name": "Jimi"},
{"_id": "54af50622071121b25402dc3", "user_id": 1, "age": 11, "name": "Eddie"},
]
@db_name "basic-find"

setup do
UserDocs.setup(@db_name)
end

class IgnoreDesignDocsForAllDocsIndexTests(mango.DbPerClass):
def test_should_not_return_design_docs(self):
self.db.save_docs(DOCS)
docs = self.db.find({"_id": {"$gte": None}})
assert len(docs) == 2
test "simple find" do
{:ok, docs} = MangoDatabase.find(@db_name, %{"age" => %{"$lt" => 35}})
user_ids = Enum.map(docs, fn doc -> doc["user_id"] end)

assert user_ids == [9, 1, 7]
end
end
33 changes: 33 additions & 0 deletions test/elixir/test/mango/06_basic_text_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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 ElemMatchTests do
use CouchTestCase

@db_name "basic-text-elem-match"

setup do
FriendDocs.setup(@db_name, "text")
end

test "elem match non object" do
q = %{"bestfriends" => %{"$elemMatch" => %{"$eq" => "Wolverine", "$eq" => "Cyclops"}}}
{:ok, docs} = MangoDatabase.find(@db_name, q)
assert length(docs) == 1
assert Enum.at(docs, 0)["bestfriends"] == ["Wolverine", "Cyclops"]

q = %{"results" => %{"$elemMatch" => %{"$gte" => 80, "$lt" => 85}}}
{:ok, docs} = MangoDatabase.find(@db_name, q)
assert length(docs) == 1
assert Enum.at(docs, 0)["results"] == [82, 85, 88]
end
end
Loading