Skip to content

Commit 20cbdc4

Browse files
committed
Add tests for the Hover Provider and Message Router
This commit adds tests for the Hover Provider and the Message Router. This commit also adds helper Mock objects for the JSON RPC handler and Pupept Resource objects which are needed in unit testing. The `--no-preload` option is added in spec setup to speed up tests which do not require the full Puppet initialization, typically these are the unit tests.
1 parent 2700c4c commit 20cbdc4

File tree

3 files changed

+618
-1
lines changed

3 files changed

+618
-1
lines changed

server/spec/integration/puppet-languageserver/hover_provider_spec.rb

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,85 @@
4040
end
4141
end
4242

43+
context "Given a class definition in the manifest" do
44+
let(:content) { <<-EOT
45+
class Test::NoParams {
46+
user { 'Alice':
47+
ensure => 'present',
48+
name => 'name',
49+
}
50+
}
51+
52+
class Test::WithParams (String $version = 'Bob') {
53+
user { $version:
54+
ensure => 'present',
55+
name => 'name',
56+
}
57+
}
58+
EOT
59+
}
60+
61+
describe 'when cursor is on the class keyword' do
62+
let(:line_num) { 0 }
63+
let(:char_num) { 3 }
64+
65+
it 'should return class description' do
66+
pending('Not implemented')
67+
result = subject.resolve(content, line_num, char_num)
68+
69+
expect(result['contents']).to start_with("**class** keyword\n")
70+
end
71+
end
72+
73+
describe 'when cursor is on the class name' do
74+
let(:line_num) { 0 }
75+
let(:char_num) { 14 }
76+
77+
it 'should return class description' do
78+
pending('Not implemented')
79+
result = subject.resolve(content, line_num, char_num)
80+
81+
expect(result['contents']).to start_with("**class** keyword\n")
82+
end
83+
end
84+
85+
describe 'when cursor is on the property type in a class definition' do
86+
let(:line_num) { 7 }
87+
let(:char_num) { 27 }
88+
89+
it 'should return type information' do
90+
pending('Not implemented')
91+
result = subject.resolve(content, line_num, char_num)
92+
93+
expect(result['contents']).to start_with("**String** keyword\n")
94+
end
95+
end
96+
97+
describe 'when cursor is on the property name in a class definition' do
98+
let(:line_num) { 7 }
99+
let(:char_num) { 36 }
100+
101+
it 'should not return any information' do
102+
pending('Not implemented')
103+
result = subject.resolve(content, line_num, char_num)
104+
105+
expect(result['contents']).to eq('')
106+
end
107+
end
108+
109+
describe 'when cursor is on the property default value in a class definition' do
110+
let(:line_num) { 7 }
111+
let(:char_num) { 44 }
112+
113+
it 'should not return any information' do
114+
pending('Not implemented')
115+
result = subject.resolve(content, line_num, char_num)
116+
117+
expect(result['contents']).to eq('')
118+
end
119+
end
120+
end
121+
43122
context "Given a resource in the manifest" do
44123
let(:content) { <<-EOT
45124
user { 'Bob':

server/spec/spec_helper.rb

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
# Currently there is no way to re-initialize the puppet loader so for the moment
1212
# all tests must run off the single puppet config settings instead of per example setting
13-
server_options = PuppetLanguageServer::CommandLineParser.parse([])
13+
server_options = PuppetLanguageServer::CommandLineParser.parse(['--no-preload'])
1414
server_options[:puppet_settings] = ['--vardir',File.join(fixtures_dir,'cache'),
1515
'--confdir',File.join(fixtures_dir,'confdir')]
1616
PuppetLanguageServer::init_puppet(server_options)
@@ -25,3 +25,49 @@
2525
"be a Completion Item with a data type in the list of #{value}"
2626
end
2727
end
28+
29+
# Mock ojects
30+
class MockJSONRPCHandler < PuppetLanguageServer::JSONRPCHandler
31+
attr_accessor :socket
32+
attr_accessor :simple_tcp_server
33+
34+
def post_init
35+
end
36+
37+
def unbind
38+
end
39+
40+
def receive_data(data)
41+
end
42+
43+
def error?
44+
false
45+
end
46+
47+
def send_data(data)
48+
true
49+
end
50+
51+
def close_connection_after_writing
52+
end
53+
54+
def close_connection
55+
end
56+
end
57+
58+
class MockResource
59+
attr_accessor :title
60+
61+
def initialize(type_name = 'type' + rand(65536).to_s, title = 'resource' + rand(65536).to_s)
62+
@title = title
63+
@type = type_name
64+
end
65+
66+
def to_manifest
67+
<<-HEREDOC
68+
#{@type} { '#{@title}':
69+
ensure => present
70+
}
71+
HEREDOC
72+
end
73+
end

0 commit comments

Comments
 (0)