Skip to content

Commit e79fc55

Browse files
committed
(GH-140) Fix unit tests for zero resource node graph
Previously in commit 30e8fec 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.
1 parent 67a80a0 commit e79fc55

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

server/spec/spec_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ def close_connection
5555
end
5656
end
5757

58+
class MockRelationshipGraph
59+
attr_accessor :vertices
60+
def initialize()
61+
end
62+
end
63+
5864
class MockResource
5965
attr_accessor :title
6066

server/spec/unit/puppet-languageserver/message_router_spec.rb

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,22 +212,47 @@
212212
end
213213

214214
context 'and successfully generate the node graph' do
215-
let(:relationship_graph) { double('graph') }
215+
let(:relationship_graph) { MockRelationshipGraph.new() }
216216
before(:each) do
217-
expect(relationship_graph).to receive(:to_dot).with(Hash).and_return(dot_content)
218217
expect(PuppetLanguageServer::PuppetParserHelper).to receive(:compile_to_pretty_relationship_graph).with(file_content).and_return(relationship_graph)
219218
end
220219

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

224-
subject.receive_request(request)
226+
it 'should reply with dotContent' do
227+
expect(request).to receive(:reply_result).with(hash_including('dotContent' => dot_content))
228+
229+
subject.receive_request(request)
230+
end
231+
232+
it 'should not reply with error' do
233+
expect(request).to_not receive(:reply_result).with(hash_including('error'))
234+
235+
subject.receive_request(request)
236+
end
225237
end
226238

227-
it 'should not reply with error' do
228-
expect(request).to_not receive(:reply_result).with(hash_including('error'))
239+
context 'with zero resources' do
240+
before(:each) do
241+
relationship_graph.vertices = []
242+
expect(relationship_graph).to receive(:to_dot).with(Hash).never
243+
end
229244

230-
subject.receive_request(request)
245+
it 'should reply with the error text' do
246+
expect(request).to receive(:reply_result).with(hash_including('error' => /no resources/))
247+
248+
subject.receive_request(request)
249+
end
250+
251+
it 'should not reply with dotContent' do
252+
expect(request).to_not receive(:reply_result).with(hash_including('dotContent'))
253+
254+
subject.receive_request(request)
255+
end
231256
end
232257
end
233258
end

0 commit comments

Comments
 (0)