Skip to content

Commit

Permalink
add riak_test for legacy s3 rewrite module.
Browse files Browse the repository at this point in the history
  • Loading branch information
ksauzz committed Jan 6, 2015
1 parent 3bfdf3f commit d1c3d02
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions riak_test/tests/legacy_s3_rewrite_test.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
%% ---------------------------------------------------------------------
%%
%% Copyright (c) 2007-2015 Basho Technologies, Inc. All Rights Reserved.
%%
%% This file is provided to you 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.
%%
%% ---------------------------------------------------------------------

-module(legacy_s3_rewrite_test).

%% @doc `riak_test' module for testing object get behavior.

-export([confirm/0]).
-include_lib("erlcloud/include/erlcloud_aws.hrl").
-include_lib("eunit/include/eunit.hrl").

-define(TEST_BUCKET, "legacy-s3-rewrite-test").

confirm() ->
%% NOTE: This 'cs_src_root' path must appear in
%% ~/.riak_test.config in the 'rt_cs_dev' section, 'src_paths'
%% subsection.
CsSrcDir = rt_cs_dev:srcpath(cs_src_root),
lager:debug("cs_src_root = ~p", [CsSrcDir]),

{UserConfig, {RiakNodes, _CSNodes, _Stanchion}} = rtcs:setup(1, [{cs, cs_config()}]),
ok = erlcloud_s3:create_bucket(?TEST_BUCKET, UserConfig),
CsPortStr = integer_to_list(rtcs:cs_port(hd(RiakNodes))),

Cmd = os:find_executable("make"),
Args = ["test-python"],
Env = [{"CS_HTTP_PORT", CsPortStr},
{"AWS_ACCESS_KEY_ID", UserConfig#aws_config.access_key_id},
{"AWS_SECRET_ACCESS_KEY", UserConfig#aws_config.secret_access_key},
{"CS_BUCKET", ?TEST_BUCKET}],
case execute_cmd(Cmd, [{cd, CsSrcDir}, {env, Env}, {args, Args}]) of
ok ->
pass;
{error, Reason} ->
lager:error("Error : ~p", [Reason]),
error({external_client_tests, Reason})
end.

execute_cmd(Cmd, Opts) ->
lager:info("Command: ~s", [Cmd]),
lager:info("Options: ~p", [Opts]),
Port = open_port({spawn_executable, Cmd},
[in, exit_status, binary,
stream, stderr_to_stdout,{line, 200} | Opts]),
get_cmd_result(Port).

get_cmd_result(Port) ->
WaitTime = rt_config:get(rt_max_wait_time),
receive
{Port, {data, {Flag, Line}}} when Flag =:= eol orelse Flag =:= noeol ->
lager:info(Line),
get_cmd_result(Port);
{Port, {exit_status, 0}} ->
ok;
{Port, {exit_status, Status}} ->
{error, {exit_status, Status}};
{Port, Other} ->
lager:warning("Other data from port: ~p", [Other]),
get_cmd_result(Port)
after WaitTime * 2 ->
{error, timeout}
end.

cs_config() ->
[
rtcs:lager_config(),
{riak_cs,
[
{proxy_get, enabled},
{anonymous_user_creation, true},
{riak_pb_port, 10017},
{stanchion_port, 9095},
{cs_version, 010300},
{enforce_multipart_part_size, false},
{max_buckets_per_user, 150},
{rewrite_module, riak_cs_s3_rewrite_legacy}
]
}].

0 comments on commit d1c3d02

Please sign in to comment.