test/test_client.rb in octoparts-0.0.7 vs test/test_client.rb in octoparts-0.0.8
- old
+ new
@@ -113,10 +113,46 @@
@client.invoke(nil)
end
end
end
+ sub_test_case "#invalidate_cache" do
+ test "post /invalidate/part/PART_ID" do
+ VCR.use_cassette 'invalidate_cache_with_part_id' do
+ stub_request(:post, 'localhost:9000')
+ @client.invalidate_cache('echo')
+ assert_requested(:post, 'http://localhost:9000/octoparts/2/cache/invalidate/part/echo')
+ end
+ end
+
+ test "post /invalidate/part/PART_ID/PARAM_NAME/PARAM_VALUE" do
+ VCR.use_cassette 'invalidate_cache_with_part_id_and_key_value' do
+ stub_request(:post, 'localhost:9000')
+ @client.invalidate_cache('echo', param_name: 'fooValue', param_value: 'test')
+ assert_requested(:post, 'http://localhost:9000/octoparts/2/cache/invalidate/part/echo/fooValue/test')
+ end
+ end
+ end
+
+ sub_test_case "#invalidate_cache_group" do
+ test "post /invalidate/cache-group/GROUP_NAME/parts" do
+ VCR.use_cassette 'invalidate_cache_group_with_group_name' do
+ stub_request(:post, 'localhost:9000')
+ @client.invalidate_cache_group('echo_group')
+ assert_requested(:post, 'http://localhost:9000/octoparts/2/cache/invalidate/cache-group/echo_group/parts')
+ end
+ end
+
+ test "post /invalidate/cache-group/GROUP_NAME/params/PARAM_VALUE" do
+ VCR.use_cassette 'invalidate_cache_group_with_param_value' do
+ stub_request(:post, 'localhost:9000')
+ @client.invalidate_cache_group('echo_group', param_value: 'fooValue')
+ assert_requested(:post, 'http://localhost:9000/octoparts/2/cache/invalidate/cache-group/echo_group/params/fooValue')
+ end
+ end
+ end
+
sub_test_case "timeout" do
setup do
@endpoint = Octoparts.configuration.endpoint
Octoparts.configure do |c|
# avoiding connection failed error, sorry heroku...
@@ -143,9 +179,18 @@
Octoparts.configure do |c|
c.timeout_sec = 0
end
assert_raise @exception_class do
Octoparts::Client.new.get('/')
+ end
+ end
+ end
+
+ sub_test_case "error case" do
+ test "500 error" do
+ stub_request(:any, 'localhost:9000/500').to_return(status: 500, body: 'NG', headers: { 'Content-Length' => 2})
+ assert_raise Octoparts::ServerError do
+ Octoparts::Client.new(timeout_sec: 0).get('/500')
end
end
end
end