Skip to content

Commit

Permalink
(GH-140) Fix unit tests for zero resource node graph
Browse files Browse the repository at this point in the history
Previously in commit 30e8fecb683 an error message was raised for node graphs
with no resources however the unit tests were not modified for this scenario.
This commit updates the unit tests for these test scenarios.
  • Loading branch information
glennsarti committed Sep 20, 2017
1 parent 5ad240f commit e5ca7cd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def close_connection
end
end

class MockRelationshipGraph
attr_accessor :vertices
def initialize()
end
end

class MockResource
attr_accessor :title

Expand Down
41 changes: 33 additions & 8 deletions spec/unit/puppet-languageserver/message_router_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,47 @@
end

context 'and successfully generate the node graph' do
let(:relationship_graph) { double('graph') }
let(:relationship_graph) { MockRelationshipGraph.new() }
before(:each) do
expect(relationship_graph).to receive(:to_dot).with(Hash).and_return(dot_content)
expect(PuppetLanguageServer::PuppetParserHelper).to receive(:compile_to_pretty_relationship_graph).with(file_content).and_return(relationship_graph)
end

it 'should reply with dotContent' do
expect(request).to receive(:reply_result).with(hash_including('dotContent' => dot_content))
context 'with one or more resources' do
before(:each) do
relationship_graph.vertices = [double('node1'),double('node2')]
expect(relationship_graph).to receive(:to_dot).with(Hash).and_return(dot_content)
end

subject.receive_request(request)
it 'should reply with dotContent' do
expect(request).to receive(:reply_result).with(hash_including('dotContent' => dot_content))

subject.receive_request(request)
end

it 'should not reply with error' do
expect(request).to_not receive(:reply_result).with(hash_including('error'))

subject.receive_request(request)
end
end

it 'should not reply with error' do
expect(request).to_not receive(:reply_result).with(hash_including('error'))
context 'with zero resources' do
before(:each) do
relationship_graph.vertices = []
expect(relationship_graph).to receive(:to_dot).with(Hash).never
end

subject.receive_request(request)
it 'should reply with the error text' do
expect(request).to receive(:reply_result).with(hash_including('error' => /no resources/))

subject.receive_request(request)
end

it 'should not reply with dotContent' do
expect(request).to_not receive(:reply_result).with(hash_including('dotContent'))

subject.receive_request(request)
end
end
end
end
Expand Down

0 comments on commit e5ca7cd

Please sign in to comment.