summaryrefslogtreecommitdiffstats
path: root/test/net_test.rb
blob: 705ca7389607d28d28dc9ddf111ae146bdaccbd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'test_helper'

class NetTest < HCl::TestCase

  def test_configure
    assert_equal 'bob', http.login
    assert_equal 'secret', http.password
    assert_equal 'bobclock', http.subdomain
  end

  def test_redirect_failure
    register_status(:get, "/taco", 302)
    assert_raises(HCl::HarvestMiddleware::Failure) { http.get('/taco') }
  end

  def test_auth_failure
    register_status(:get, "/burrito", 403)
    assert_raises(HCl::HarvestMiddleware::AuthFailure) { http.get('/burrito') }
  end

  def test_throttle_failure
    register_status(:get, "/sushi", 503)
    assert_raises(HCl::HarvestMiddleware::ThrottleFailure) { http.get('/sushi') }
  end

  def test_generic_failure
    register_status(:get, "/kimchee", 500)
    assert_raises(HCl::HarvestMiddleware::Failure) { http.get('/kimchee') }
  end

  def test_http_deep_unescape
    register_uri(:get, "/foo", {
      status:'gotten &amp; got!',
      comparisons:['burrito &gt; taco', 'rain &lt; sun']
    })
    body = http.get 'foo'
    assert_equal 'gotten & got!', body[:status]
    assert_equal 'burrito > taco', body[:comparisons][0]
    assert_equal 'rain < sun', body[:comparisons][1]
  end

  def test_http_get
    register_uri(:get, "/foo", {message:'gotten!'})
    body = http.get 'foo'
    assert_equal 'gotten!', body[:message]
  end

  def test_http_post
    register_uri(:post, "/foo", {message:'posted!'})
    body = http.post 'foo', {pizza:'taco'}
    assert_equal 'posted!', body[:message]
  end

  def test_http_delete
    register_uri(:delete, "/foo", {message:'wiped!'})
    body = http.delete 'foo'
    assert_equal 'wiped!', body[:message]
  end
end