Blob Blame History Raw
From: Peter Lemenkov <lemenkov@gmail.com>
Date: Mon, 18 Apr 2016 14:02:36 +0300
Subject: [PATCH] Fix tests for Jiffy

Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>

diff --git a/test/couchdb/couchdb_attachments_tests.erl b/test/couchdb/couchdb_attachments_tests.erl
index 24416e52a..022a170ad 100644
--- a/test/couchdb/couchdb_attachments_tests.erl
+++ b/test/couchdb/couchdb_attachments_tests.erl
@@ -373,7 +373,7 @@ should_get_doc_with_att_data(compressed, {Data, {_, DocUrl, _}}) ->
         {ok, Code, _, Body} = test_request:get(
             Url, [{"Accept", "application/json"}]),
         ?assertEqual(200, Code),
-        Json = ejson:decode(Body),
+        Json = ?JSON_DECODE(Body),
         AttJson = couch_util:get_nested_json_value(
             Json, [<<"_attachments">>, ?ATT_TXT_NAME]),
         AttData = couch_util:get_nested_json_value(
@@ -389,7 +389,7 @@ should_get_doc_with_att_data({text, _}, {Data, {_, DocUrl, _}}) ->
         {ok, Code, _, Body} = test_request:get(
             Url, [{"Accept", "application/json"}]),
         ?assertEqual(200, Code),
-        Json = ejson:decode(Body),
+        Json = ?JSON_DECODE(Body),
         AttJson = couch_util:get_nested_json_value(
             Json, [<<"_attachments">>, ?ATT_TXT_NAME]),
         AttData = couch_util:get_nested_json_value(
@@ -405,7 +405,7 @@ should_get_doc_with_att_data({binary, _}, {Data, {_, DocUrl, _}}) ->
         {ok, Code, _, Body} = test_request:get(
             Url, [{"Accept", "application/json"}]),
         ?assertEqual(200, Code),
-        Json = ejson:decode(Body),
+        Json = ?JSON_DECODE(Body),
         AttJson = couch_util:get_nested_json_value(
             Json, [<<"_attachments">>, ?ATT_BIN_NAME]),
         AttData = couch_util:get_nested_json_value(
@@ -422,7 +422,7 @@ should_get_doc_with_att_data_stub(compressed, {Data, {_, DocUrl, _}}) ->
         {ok, Code, _, Body} = test_request:get(
             Url, [{"Accept", "application/json"}]),
         ?assertEqual(200, Code),
-        Json = ejson:decode(Body),
+        Json = ?JSON_DECODE(Body),
         {AttJson} = couch_util:get_nested_json_value(
             Json, [<<"_attachments">>, ?ATT_TXT_NAME]),
         ?assertEqual(<<"gzip">>,
@@ -438,7 +438,7 @@ should_get_doc_with_att_data_stub({text, _}, {Data, {_, DocUrl, _}}) ->
         {ok, Code, _, Body} = test_request:get(
             Url, [{"Accept", "application/json"}]),
         ?assertEqual(200, Code),
-        Json = ejson:decode(Body),
+        Json = ?JSON_DECODE(Body),
         {AttJson} = couch_util:get_nested_json_value(
             Json, [<<"_attachments">>, ?ATT_TXT_NAME]),
         ?assertEqual(<<"gzip">>,
@@ -455,7 +455,7 @@ should_get_doc_with_att_data_stub({binary, _}, {Data, {_, DocUrl, _}}) ->
         {ok, Code, _, Body} = test_request:get(
             Url, [{"Accept", "application/json"}]),
         ?assertEqual(200, Code),
-        Json = ejson:decode(Body),
+        Json = ?JSON_DECODE(Body),
         {AttJson} = couch_util:get_nested_json_value(
             Json, [<<"_attachments">>, ?ATT_BIN_NAME]),
         ?assertEqual(undefined,
@@ -512,7 +512,7 @@ should_create_compressible_att_with_ctype_params({Host, DbName}) ->
         {ok, Code1, _, Body} = test_request:get(
             DocUrl ++ "?att_encoding_info=true"),
         ?assertEqual(200, Code1),
-        Json = ejson:decode(Body),
+        Json = ?JSON_DECODE(Body),
         {AttJson} = couch_util:get_nested_json_value(
             Json, [<<"_attachments">>, ?ATT_TXT_NAME]),
         ?assertEqual(<<"gzip">>,
@@ -568,7 +568,7 @@ request(Method, Url, Headers, Body) ->
     [Header, Body1] = re:split(R, "\r\n\r\n", [{return, binary}]),
     {ok, {http_response, _, Code, _}, _} =
         erlang:decode_packet(http, Header, []),
-    Json = ejson:decode(Body1),
+    Json = ?JSON_DECODE(Body1),
     {ok, Code, Json}.
 
 create_standalone_text_att(Host, DbName) ->
@@ -599,7 +599,7 @@ create_inline_text_att(Host, DbName) ->
         }]}}
     ]},
     {ok, Code, _Headers, _Body} = test_request:put(
-        Url, [{"Content-Type", "application/json"}], ejson:encode(Doc)),
+        Url, [{"Content-Type", "application/json"}], ?JSON_ENCODE(Doc)),
     ?assertEqual(201, Code),
     string:join([Url, ?b2l(?ATT_TXT_NAME)], "/").
 
@@ -615,7 +615,7 @@ create_inline_png_att(Host, DbName) ->
         }]}}
     ]},
     {ok, Code, _Headers, _Body} = test_request:put(
-        Url, [{"Content-Type", "application/json"}], ejson:encode(Doc)),
+        Url, [{"Content-Type", "application/json"}], ?JSON_ENCODE(Doc)),
     ?assertEqual(201, Code),
     string:join([Url, ?b2l(?ATT_BIN_NAME)], "/").
 
diff --git a/test/couchdb/couchdb_vhosts_tests.erl b/test/couchdb/couchdb_vhosts_tests.erl
index 94b195769..0ae5a13dd 100644
--- a/test/couchdb/couchdb_vhosts_tests.erl
+++ b/test/couchdb/couchdb_vhosts_tests.erl
@@ -157,7 +157,7 @@ should_return_database_info({Url, DbName}) ->
         ok = couch_config:set("vhosts", "example.com", "/" ++ DbName, false),
         case test_request:get(Url, [], [{host_header, "example.com"}]) of
             {ok, _, _, Body} ->
-                {JsonBody} = ejson:decode(Body),
+                {JsonBody} = ?JSON_DECODE(Body),
                 ?assert(proplists:is_defined(<<"db_name">>, JsonBody));
             Else ->
                 erlang:error({assertion_failed,
@@ -173,7 +173,7 @@ should_return_revs_info({Url, DbName}) ->
         case test_request:get(Url ++ "/doc1?revs_info=true", [],
                               [{host_header, "example.com"}]) of
             {ok, _, _, Body} ->
-                {JsonBody} = ejson:decode(Body),
+                {JsonBody} = ?JSON_DECODE(Body),
                 ?assert(proplists:is_defined(<<"_revs_info">>, JsonBody));
             Else ->
                 erlang:error({assertion_failed,
@@ -205,7 +205,7 @@ should_return_virtual_request_path_field_in_request({Url, DbName}) ->
                               false),
         case test_request:get(Url, [], [{host_header, "example1.com"}]) of
             {ok, _, _, Body} ->
-                {Json} = ejson:decode(Body),
+                {Json} = ?JSON_DECODE(Body),
                 ?assertEqual(<<"/">>,
                              proplists:get_value(<<"requested_path">>, Json));
             Else ->
@@ -223,7 +223,7 @@ should_return_real_request_path_field_in_request({Url, DbName}) ->
                               false),
         case test_request:get(Url, [], [{host_header, "example1.com"}]) of
             {ok, _, _, Body} ->
-                {Json} = ejson:decode(Body),
+                {Json} = ?JSON_DECODE(Body),
                 Path = ?l2b("/" ++ DbName ++ "/_design/doc1/_show/test"),
                 ?assertEqual(Path, proplists:get_value(<<"path">>, Json));
             Else ->
@@ -240,7 +240,7 @@ should_match_wildcard_vhost({Url, DbName}) ->
                               "/" ++ DbName ++ "/_design/doc1/_rewrite", false),
         case test_request:get(Url, [], [{host_header, "test.example.com"}]) of
             {ok, _, _, Body} ->
-                {Json} = ejson:decode(Body),
+                {Json} = ?JSON_DECODE(Body),
                 Path = ?l2b("/" ++ DbName ++ "/_design/doc1/_show/test"),
                 ?assertEqual(Path, proplists:get_value(<<"path">>, Json));
             Else ->
@@ -258,7 +258,7 @@ should_return_db_info_for_wildcard_vhost_for_custom_db({Url, DbName}) ->
         Host = DbName ++ ".example1.com",
         case test_request:get(Url, [], [{host_header, Host}]) of
             {ok, _, _, Body} ->
-                {JsonBody} = ejson:decode(Body),
+                {JsonBody} = ?JSON_DECODE(Body),
                 ?assert(proplists:is_defined(<<"db_name">>, JsonBody));
             Else ->
                 erlang:error({assertion_failed,
@@ -275,7 +275,7 @@ should_replace_rewrite_variables_for_db_and_doc({Url, DbName}) ->
         Host = "doc1." ++ DbName ++ ".example1.com",
         case test_request:get(Url, [], [{host_header, Host}]) of
             {ok, _, _, Body} ->
-                {Json} = ejson:decode(Body),
+                {Json} = ?JSON_DECODE(Body),
                 Path = ?l2b("/" ++ DbName ++ "/_design/doc1/_show/test"),
                 ?assertEqual(Path, proplists:get_value(<<"path">>, Json));
             Else ->
@@ -293,7 +293,7 @@ should_return_db_info_for_vhost_with_resource({Url, DbName}) ->
         ReqUrl = Url ++ "/test",
         case test_request:get(ReqUrl, [], [{host_header, "example.com"}]) of
             {ok, _, _, Body} ->
-                {JsonBody} = ejson:decode(Body),
+                {JsonBody} = ?JSON_DECODE(Body),
                 ?assert(proplists:is_defined(<<"db_name">>, JsonBody));
             Else ->
                 erlang:error({assertion_failed,
@@ -311,7 +311,7 @@ should_return_revs_info_for_vhost_with_resource({Url, DbName}) ->
         ReqUrl = Url ++ "/test/doc1?revs_info=true",
         case test_request:get(ReqUrl, [], [{host_header, "example.com"}]) of
             {ok, _, _, Body} ->
-                {JsonBody} = ejson:decode(Body),
+                {JsonBody} = ?JSON_DECODE(Body),
                 ?assert(proplists:is_defined(<<"_revs_info">>, JsonBody));
             Else ->
                 erlang:error({assertion_failed,
@@ -328,7 +328,7 @@ should_return_db_info_for_vhost_with_wildcard_resource({Url, DbName}) ->
         Host = DbName ++ ".example2.com",
         case test_request:get(ReqUrl, [], [{host_header, Host}]) of
             {ok, _, _, Body} ->
-                {JsonBody} = ejson:decode(Body),
+                {JsonBody} = ?JSON_DECODE(Body),
                 ?assert(proplists:is_defined(<<"db_name">>, JsonBody));
             Else ->
                 erlang:error({assertion_failed,
@@ -345,7 +345,7 @@ should_return_path_for_vhost_with_wildcard_host({Url, DbName}) ->
                               false),
         case test_request:get(Url ++ "/test1") of
             {ok, _, _, Body} ->
-                {Json} = ejson:decode(Body),
+                {Json} = ?JSON_DECODE(Body),
                 Path = ?l2b("/" ++ DbName ++ "/_design/doc1/_show/test"),
                 ?assertEqual(Path, proplists:get_value(<<"path">>, Json));
             Else ->
@@ -361,7 +361,7 @@ should_require_auth({Url, _}) ->
         case test_request:get(Url, [], [{host_header, "oauth-example.com"}]) of
             {ok, Code, _, Body} ->
                 ?assertEqual(401, Code),
-                {JsonBody} = ejson:decode(Body),
+                {JsonBody} = ?JSON_DECODE(Body),
                 ?assertEqual(<<"unauthorized">>,
                              couch_util:get_value(<<"error">>, JsonBody));
             Else ->
@@ -395,7 +395,7 @@ should_succeed_oauth({Url, _}) ->
         case test_request:get(OAuthUrl, [], [{host_header, Host}]) of
             {ok, Code, _, Body} ->
                 ?assertEqual(200, Code),
-                {JsonBody} = ejson:decode(Body),
+                {JsonBody} = ?JSON_DECODE(Body),
                 ?assertEqual(<<"test">>,
                              couch_util:get_value(<<"name">>, JsonBody));
             Else ->
@@ -429,7 +429,7 @@ should_fail_oauth_with_wrong_credentials({Url, _}) ->
         case test_request:get(OAuthUrl, [], [{host_header, Host}]) of
             {ok, Code, _, Body} ->
                 ?assertEqual(401, Code),
-                {JsonBody} = ejson:decode(Body),
+                {JsonBody} = ?JSON_DECODE(Body),
                 ?assertEqual(<<"unauthorized">>,
                              couch_util:get_value(<<"error">>, JsonBody));
             Else ->
diff --git a/test/couchdb/couchdb_views_tests.erl b/test/couchdb/couchdb_views_tests.erl
index 316029b0d..8c206b9d3 100644
--- a/test/couchdb/couchdb_views_tests.erl
+++ b/test/couchdb/couchdb_views_tests.erl
@@ -500,7 +500,7 @@ query_view(DbName, DDoc, View, Stale) ->
                _ -> "?stale=" ++ atom_to_list(Stale)
            end),
     ?assertEqual(200, Code),
-    {Props} = ejson:decode(Body),
+    {Props} = ?JSON_DECODE(Body),
     couch_util:get_value(<<"rows">>, Props, []).
 
 check_rows_value(Rows, Value) ->
@@ -589,7 +589,7 @@ wait_view_compact_done(DbName, DDocId, N) ->
     {ok, Code, _Headers, Body} = test_request:get(
         db_url(DbName) ++ "/" ++ ?b2l(DDocId) ++ "/_info"),
     ?assertEqual(200, Code),
-    {Info} = ejson:decode(Body),
+    {Info} = ?JSON_DECODE(Body),
     {IndexInfo} = couch_util:get_value(<<"view_index">>, Info),
     CompactRunning = couch_util:get_value(<<"compact_running">>, IndexInfo),
     case CompactRunning of
diff --git a/test/couchdb/fixtures/os_daemon_configer.escript.in b/test/couchdb/fixtures/os_daemon_configer.escript.in
index d2ecfa8ac..8b77480fd 100755
--- a/test/couchdb/fixtures/os_daemon_configer.escript.in
+++ b/test/couchdb/fixtures/os_daemon_configer.escript.in
@@ -1,6 +1,6 @@
 #! /usr/bin/env escript
 %% -*- erlang -*-
-%%! -DTEST -pa @abs_top_builddir@/src/ejson
+%%! -DTEST
 %%
 %% 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
@@ -19,11 +19,11 @@ read() ->
         eof ->
             stop;
         Data ->
-            ejson:decode(Data)
+            try jiffy:decode(Data) catch throw:Error -> throw({invalid_json, Error}) end
     end.
 
 write(Mesg) ->
-    Data = iolist_to_binary(ejson:encode(Mesg)),
+    Data = iolist_to_binary(jiffy:encode(Mesg, [force_utf8])),
     io:format(binary_to_list(Data) ++ "\n", []).
 
 get_cfg(Section) ->
diff --git a/test/couchdb/run.in b/test/couchdb/run.in
index 5286da37b..3e10410bc 100644
--- a/test/couchdb/run.in
+++ b/test/couchdb/run.in
@@ -99,12 +99,7 @@ run_tests(Mods, Options) ->
 
 init_code_path() ->
     Paths = [
-        "couchdb",
-        "ejson",
-        "erlang-oauth",
-        "ibrowse",
-        "mochiweb",
-        "snappy"
+        "couchdb"
     ],
     lists:foreach(fun(Name) ->
         code:add_patha(filename:join([?BUILDDIR, "src", Name]))