spec/unit/indirector/report/rest_spec.rb in puppet-3.2.1 vs spec/unit/indirector/report/rest_spec.rb in puppet-3.2.2

- old
+ new

@@ -20,6 +20,47 @@ end it "should use the :report SRV service" do Puppet::Transaction::Report::Rest.srv_service.should == :report end + + let(:model) { Puppet::Transaction::Report } + let(:terminus_class) { Puppet::Transaction::Report::Rest } + let(:terminus) { model.indirection.terminus(:rest) } + let(:indirection) { model.indirection } + + before(:each) do + Puppet::Transaction::Report.indirection.terminus_class = :rest + end + + def mock_response(code, body, content_type='text/plain', encoding=nil) + obj = stub('http 200 ok', :code => code.to_s, :body => body) + obj.stubs(:[]).with('content-type').returns(content_type) + obj.stubs(:[]).with('content-encoding').returns(encoding) + obj + end + + def save_request(key, instance, options={}) + Puppet::Indirector::Request.new(:report, :find, key, instance, options) + end + + describe "#save" do + let(:http_method) { :put } + let(:response) { mock_response(200, 'body') } + let(:connection) { stub('mock http connection', :put => response, :verify_callback= => nil) } + let(:instance) { model.new('the thing', 'some contents') } + let(:request) { save_request(instance.name, instance) } + + before :each do + terminus.stubs(:network).returns(connection) + end + + it "deserializes the response as an array of report processor names" do + processors = ["store", "http"] + body = YAML.dump(processors) + response = mock_response('200', body, 'text/yaml') + connection.expects(:put).returns response + + terminus.save(request).should == ["store", "http"] + end + end end