Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
Ensure stdout is returned from #execute
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Lane committed Mar 12, 2023
1 parent 260e864 commit af47831
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
7 changes: 5 additions & 2 deletions lib/kitchen/terraform/transport/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ class Connection < ::Kitchen::Transport::Exec::Connection
# #execute executes a Terraform CLI command on the local host.
#
# @param command [String] the Terraform command to be executed locally.
# @return [String] the standard output of the command.
# @raise [Kitchen::TransportFailed] if the command does not exit successfully.
def execute(command)
super "#{client} #{command}"

stdout
end

# #run_command executes a command in a subshell on the local running system.
Expand All @@ -41,7 +44,7 @@ def execute(command)
# @raise [Kitchen::ShellOut::ShellCommandFailed] if the command fails.
# @raise [Kitchen::StandardError] for all other unexpected exceptions.
def run_command(command, options = {})
super command, options.merge(
self.stdout = super command, options.merge(
cwd: root_module_directory,
environment: environment.merge("LC_ALL" => nil, "TF_IN_AUTOMATION" => "true"),
timeout: command_timeout,
Expand All @@ -50,7 +53,7 @@ def run_command(command, options = {})

private

attr_accessor :client, :command_timeout, :environment, :options, :root_module_directory
attr_accessor :client, :command_timeout, :environment, :options, :root_module_directory, :stdout

# #init_options initializes incoming options for use by the object.
#
Expand Down
15 changes: 9 additions & 6 deletions spec/lib/kitchen/terraform/transport/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
instance_double ::Mixlib::ShellOut
end

let :stdout do
instance_double ::String
end

specify "should invoke the ShellOut superclass implementation with the client and options configured" do
allow(subject).to receive(:run_from_file_command).with("#{client} #{command}").and_return "#{client} #{command}"
allow(subject).to receive :close
Expand All @@ -88,13 +92,12 @@
timeout: command_timeout,
})
).and_return shell_out
allow(shell_out).to receive :run_command
allow(shell_out).to receive :execution_time
allow(shell_out).to receive :error!
allow(shell_out).to receive(:stdout).and_return stdout

expect(shell_out).to receive :run_command
expect(shell_out).to receive :execution_time
expect(shell_out).to receive :error!
expect(shell_out).to receive :stdout

subject.execute command
expect(subject.execute(command)).to be stdout
end
end
end

0 comments on commit af47831

Please sign in to comment.