Skip to content

Commit

Permalink
(puppetlabsGH-256) Add acceptance tests for puppetfile resolver request
Browse files Browse the repository at this point in the history
Previosuly in commit 77878f3 a new puppetfile resolver endpoint was added.
However it was missing acceptance tests.  This commit adds a basic acceptance
smoke test for the puppetfile request.
  • Loading branch information
glennsarti committed Jun 14, 2020
1 parent c542523 commit d51a2be
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
69 changes: 69 additions & 0 deletions spec/languageserver/acceptance/end_to_end_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# Puppet resource | X | | |
# Puppet facts | X | | |
# Node graph preview | X | | |
# Puppetfile Dependencies | - | - | X |
# Completion (Typing) | X | - | - |
# Completion (Invoked) | X | - | - |
# Completion Resolution | X | - | - |
Expand Down Expand Up @@ -270,5 +271,73 @@ def path_to_uri(path)
end

context 'Processing a Control Repo' do
let(:workspace) { File.join($fixtures_dir, 'control_repos', 'valid') }
let(:puppetfile) { File.join(workspace, 'Puppetfile') }
let(:puppetfile_uri) { path_to_uri(puppetfile) }

it 'should act like a valid language server' do
# initialize_request
@client.send_data(@client.initialize_request(@client.next_seq_id, workspace))
expect(@client).to receive_message_with_request_id_within_timeout([@client.current_seq_id, 5])
result = @client.data_from_request_seq_id(@client.current_seq_id)
# Ensure required capabilites are enabled
expect(result['result']['capabilities']).to include(
{
'textDocumentSync' => 1,
'hoverProvider' => true,
'completionProvider' => {
'resolveProvider' => true,
'triggerCharacters' => ['>', '$', '[', '=']
},
'definitionProvider' => true,
'documentSymbolProvider' => true,
'workspaceSymbolProvider' => true,
'signatureHelpProvider' => {
'triggerCharacters' => ['(', ',']
},
'documentOnTypeFormattingProvider' => {
'firstTriggerCharacter' => '>' # Dynamic Registration is disabled in acceptance tests
}
}
)

# initialized event
@client.send_data(@client.initialized_notification)

# Send the client settings
@client.send_client_settings

# Wait for the language server to finish loading the Puppet information
@client.clear_messages!
@client.wait_for_puppet_loading(120)

# Open the Puppetfile
@client.clear_messages!
@client.send_data(@client.did_open_notification(puppetfile, 1))
# Wait a moment for it to load.
sleep(1)

# Puppetfile Dependencies
@client.send_data(@client.puppetfile_getdependencies_request(@client.next_seq_id, puppetfile_uri))
expect(@client).to receive_message_with_request_id_within_timeout([@client.current_seq_id, 10])
result = @client.data_from_request_seq_id(@client.current_seq_id)
# Expect something to be returned
expect(result['result']).not_to be_nil
expect(result['result']['dependencies']).not_to be_nil
expect(result['result']['dependencies']).not_to be_empty

# Start shutdown process
@client.clear_messages!
@client.send_data(@client.shutdown_request(@client.next_seq_id))
expect(@client).to receive_message_with_request_id_within_timeout([@client.current_seq_id, 5])
result = @client.data_from_request_seq_id(@client.current_seq_id)
# Expect something to be returned
expect(result['result']).to be_nil

# Exit process
@client.clear_messages!
@client.send_data(@client.exit_notification)
expect(@client).to close_within_timeout(5)
end
end
end
9 changes: 9 additions & 0 deletions spec/languageserver/spec_editor_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,15 @@ def puppet_compilenodegraph_request(seq_id, uri)
})
end

def puppetfile_getdependencies_request(seq_id, uri)
::JSON.generate({
'jsonrpc' => '2.0',
'id' => seq_id,
'method' => 'puppetfile/getDependencies',
'params' => { 'uri' => uri }
})
end

def completion_request(seq_id, uri, line, char, trigger_kind = LSP::CompletionTriggerKind::INVOKED, trigger_character = nil)
hash = {
'jsonrpc' => '2.0',
Expand Down

0 comments on commit d51a2be

Please sign in to comment.