Sha256: 442df4536eba351077b6eee3662d1bb999ab5e0726552023408505087e590039

Contents?: true

Size: 1.72 KB

Versions: 19

Compression:

Stored size: 1.72 KB

Contents

require 'helper'

module Bixby
module Test
module API
class TestHttpChannel < TestCase

  def test_exec
    url = "http://google.com/"

    json_req = JsonRequest.new("exec", {"foo" => "bar"})
    signed_json_req = SignedJsonRequest.new(json_req, "foo", "bar")

    # setup response stub
    cr = CommandResponse.new(:status => 0, :stdout => "foobar", :stderr => "")
    json_res = JsonResponse.new("success", nil, cr.to_hash)
    res_mock = mock()
    res_mock.expects(:body).once.returns(json_res.to_wire)
    HTTPI.expects(:post).with{ |r| r.kind_of?(HTTPI::Request) && r.url.to_s == url }.returns(res_mock)

    chan = HttpChannel.new(url)
    res = chan.execute(signed_json_req)

    # req should have been modified
    assert_includes signed_json_req.headers, "Content-Type"
    assert_equal "application/json", signed_json_req.headers["Content-Type"]

    assert res
    assert_kind_of JsonResponse, res
    assert res.success?

    cr = CommandResponse.from_json_response(res)
    assert cr
    assert_equal 0, cr.status
    assert_equal "foobar", cr.stdout
    assert_equal "", cr.stderr
  end

  def test_exec_download
    url = "http://google.com/"

    json_req = JsonRequest.new("exec", {"foo" => "bar"})
    signed_json_req = SignedJsonRequest.new(json_req, "foo", "bar")

    # setup response stub
    HTTPI.expects(:post).with{ |r| r.kind_of?(HTTPI::Request) && r.url.to_s == url }

    chan = HttpChannel.new(url)
    res = chan.execute_download(signed_json_req) do
    end

    # req should have been modified
    assert_includes signed_json_req.headers, "Content-Type"
    assert_equal "application/json", signed_json_req.headers["Content-Type"]

    assert res
    assert_kind_of JsonResponse, res
    assert res.success?
  end

end
end
end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
bixby-common-0.7.1 test/api/http_channel_test.rb
bixby-common-0.7.0 test/api/http_channel_test.rb
bixby-common-0.6.6 test/api/http_channel_test.rb
bixby-common-0.6.5 test/api/http_channel_test.rb
bixby-common-0.6.4 test/api/http_channel_test.rb
bixby-common-0.6.3 test/api/http_channel_test.rb
bixby-common-0.6.2 test/api/http_channel_test.rb
bixby-common-0.6.1 test/api/http_channel_test.rb
bixby-common-0.6.0 test/api/http_channel_test.rb
bixby-common-0.5.0 test/api/http_channel_test.rb
bixby-common-0.4.13 test/api/http_channel_test.rb
bixby-common-0.4.12 test/api/http_channel_test.rb
bixby-common-0.4.11 test/api/http_channel_test.rb
bixby-common-0.4.10 test/api/http_channel_test.rb
bixby-common-0.4.9 test/api/http_channel_test.rb
bixby-common-0.4.8 test/api/http_channel_test.rb
bixby-common-0.4.7 test/api/http_channel_test.rb
bixby-common-0.4.6 test/api/http_channel_test.rb
bixby-common-0.4.5 test/api/http_channel_test.rb