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

Commit

Permalink
Add Windows to Commit Tests (#504)
Browse files Browse the repository at this point in the history
* Run unit tests on Windows

* Use matrix cache versions

* Standardize bundle and lock caches

* Skip code coverage on Windows

* Use null logger in Driver tests

* Disable fail fast for RSpec

* Simplify null logging

* Add Kitchen::Transport::Exec::Connection options

* Use temp file for executable client test

* Stub #run_from_file_command in tests

* Add executable extension to tempfile

* Use string for test kitchen_root

* Stub close in tests

* Fix specification of #execute

---------

Co-authored-by: Aaron Lane <2400330-aaron-lane@users.noreply.gitlab.com>
  • Loading branch information
aaron-lane and Aaron Lane authored Mar 12, 2023
1 parent a9f519e commit 260e864
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 43 deletions.
47 changes: 32 additions & 15 deletions .github/workflows/delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
commit-compile:
name: Commit - Compile
if: ${{ github.ref_type == 'branch' }}
runs-on: ubuntu-latest
runs-on: ${{ matrix.operating-system }}-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
Expand All @@ -16,43 +16,50 @@ jobs:
ruby-version: '${{ matrix.ruby-version }}'
bundler: '2.4'
bundler-cache: true
cache-version: '1-os-${{ matrix.operating-system }}-rv-${{ matrix.ruby-version }}'
- name: Upload Bundler Lockfile
uses: actions/upload-artifact@v3
with:
name: bundler-lockfile-ruby-${{ matrix.ruby-version }}
name: bundler-lockfile-os-${{ matrix.operating-system }}-rv-${{ matrix.ruby-version }}
path: gems.locked
if-no-files-found: error
strategy:
fail-fast: false
matrix:
ruby-version:
- '2.7'
- '3.0'
- '3.1'
include:
- operating-system: ubuntu
ruby-version: '2.7'
- operating-system: ubuntu
ruby-version: '3.0'
- operating-system: ubuntu
ruby-version: '3.1'
- operating-system: windows
ruby-version: '3.1'
commit-unit-test:
name: Commit - Unit Test
needs:
- commit-compile
if: ${{ github.ref_type == 'branch' }}
runs-on: ubuntu-latest
runs-on: ${{ matrix.operating-system }}-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Download Bundler Lockfile
uses: actions/download-artifact@v3
with:
name: bundler-lockfile-ruby-${{ matrix.ruby-version }}
name: bundler-lockfile-os-${{ matrix.operating-system }}-rv-${{ matrix.ruby-version }}
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '${{ matrix.ruby-version }}'
bundler: '2.4'
bundler-cache: true
cache-version: '1-os-${{ matrix.operating-system }}-rv-${{ matrix.ruby-version }}'
- name: Run RSpec Tests
if: ${{ matrix.ruby-version != '3.1' }}
if: ${{ !matrix.code-coverage }}
run: bundle exec rake test:rspec
- name: Run RSpec Tests with Code Coverage
if: ${{ matrix.ruby-version == '3.1' }}
if: ${{ matrix.code-coverage }}
uses: paambaati/codeclimate-action@v3.2.0
env:
CC_TEST_REPORTER_ID: 7574433e1beed630cb9a171c688bb9e010d5028f00f7218d6e845fe138c65168
Expand All @@ -61,10 +68,19 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby-version:
- '2.7'
- '3.0'
- '3.1'
include:
- code-coverage: false
operating-system: ubuntu
ruby-version: '2.7'
- code-coverage: false
operating-system: ubuntu
ruby-version: '3.0'
- code-coverage: true
operating-system: ubuntu
ruby-version: '3.1'
- code-coverage: false
operating-system: windows
ruby-version: '3.1'
commit-assemble:
name: Commit - Assemble
needs:
Expand All @@ -77,13 +93,14 @@ jobs:
- name: Download Bundler Lockfile
uses: actions/download-artifact@v3
with:
name: bundler-lockfile-ruby-3.1
name: bundler-lockfile-os-ubuntu-rv-3.1
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1'
bundler: '2.4'
bundler-cache: true
cache-version: '1-os-ubuntu-rv-3.1'
- name: Build Ruby Gem
env:
GEM_PRIVATE_KEY: ${{ secrets.GEM_PRIVATE_KEY }}
Expand Down
1 change: 0 additions & 1 deletion spec/lib/kitchen/driver/terraform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
::Kitchen::Instance.new(
driver: subject,
lifecycle_hooks: ::Kitchen::LifecycleHooks.new(config, state_file),
logger: ::Kitchen::Logger.new,
platform: ::Kitchen::Platform.new(name: "test-platform"),
provisioner: ::Kitchen::Provisioner::Base.new,
state_file: state_file,
Expand Down
3 changes: 1 addition & 2 deletions spec/lib/kitchen/provisioner/terraform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
::Kitchen::Instance.new(
driver: driver,
lifecycle_hooks: ::Kitchen::LifecycleHooks.new(config, state_file),
logger: logger,
platform: ::Kitchen::Platform.new(name: "test-platform"),
provisioner: subject,
state_file: state_file,
Expand All @@ -70,7 +69,7 @@
config: driver_config,
connection: kind_of(::Kitchen::Terraform::Transport::Connection),
debug_connection: kind_of(::Kitchen::Terraform::Transport::Connection),
logger: logger,
logger: ::Kitchen.logger,
version_requirement: kind_of(::Gem::Requirement),
workspace_name: kind_of(::String),
).and_return(converge)
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/kitchen/terraform/driver/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
described_class.new(
config: config,
connection: connection,
logger: logger,
logger: ::Kitchen.logger,
workspace_name: double(::String),
version_requirement: ::Gem::Requirement.new(">= 0.1.0"),
)
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/kitchen/terraform/driver/destroy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
described_class.new(
config: config,
connection: connection,
logger: logger,
logger: ::Kitchen.logger,
workspace_name: "test-workspace",
version_requirement: ::Gem::Requirement.new(">= 0.1.0"),
)
Expand Down
12 changes: 6 additions & 6 deletions spec/lib/kitchen/terraform/inspec_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@

describe ".logger=" do
before do
described_class.logger = logger
described_class.logger = ::Kitchen.logger
end

specify "should extend the logger interface to be compatible with InSpec" do
expect(logger.logdev.filename).to be false
expect(::Kitchen.logger.logdev.filename).to be false
end

specify "should set the Inspec logger" do
expect(::Inspec::Log.logger).to be logger
expect(::Inspec::Log.logger).to be ::Kitchen.logger
end
end

Expand All @@ -42,7 +42,7 @@
end

let :full_options do
{ key: "value", logger: logger }
{ key: "value", logger: ::Kitchen.logger }
end

let :loader do
Expand All @@ -67,7 +67,7 @@
allow(loader).to receive :exit_on_load_error
allow(::Inspec::Runner).to receive(:new).with(full_options).and_return runner
allow(runner).to receive(:add_target).with profile_location
described_class.logger = logger
described_class.logger = ::Kitchen.logger
end

context "when the InSpec runner raises an error and a host is not targeted" do
Expand All @@ -84,7 +84,7 @@

context "when the InSpec runner raises an error and a host is targeted" do
let :full_options do
{ host: "test", key: "value", logger: logger }
{ host: "test", key: "value", logger: ::Kitchen.logger }
end

let :options do
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/kitchen/terraform/provisioner/converge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
config: config,
connection: connection,
debug_connection: debug_connection,
logger: logger,
logger: ::Kitchen.logger,
workspace_name: "test-workspace",
version_requirement: ::Gem::Requirement.new(">= 0.1.0"),
)
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/kitchen/terraform/system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

::RSpec.describe ::Kitchen::Terraform::System do
subject do
described_class.new configuration_attributes: configuration_attributes, logger: logger
described_class.new configuration_attributes: configuration_attributes, logger: ::Kitchen.logger
end

include_context "Kitchen::Logger"
Expand Down
24 changes: 19 additions & 5 deletions spec/lib/kitchen/terraform/transport/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,22 @@
instance_double ::String
end

let :instance_name do
instance_double ::String
end

let :kitchen_root do
# kitchen_root must support implicit string conversion
"test-kitchen-root"
end

let :options do
{
client: client,
command_timeout: command_timeout,
environment: { environment_variable_key => environment_variable_value },
instance_name: instance_name,
kitchen_root: kitchen_root,
root_module_directory: root_module_directory,
}
end
Expand All @@ -63,10 +74,8 @@
end

specify "should invoke the ShellOut superclass implementation with the client and options configured" do
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 :superclass
allow(subject).to receive(:run_from_file_command).with("#{client} #{command}").and_return "#{client} #{command}"
allow(subject).to receive :close
allow(::Mixlib::ShellOut).to receive(:new).with(
"#{client} #{command}",
including({
Expand All @@ -80,7 +89,12 @@
})
).and_return shell_out

expect(subject.execute(command)).to eq :superclass
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
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

::RSpec.describe ::Kitchen::Terraform::VerifyVersionRescueStrategy::Permissive do
subject do
described_class.new logger: logger
described_class.new logger: ::Kitchen.logger
end

include_context "Kitchen::Logger"

describe "#call" do
specify "should warn the user that the Terraform client version is unsupported" do
expect(logger).to receive :warn
expect(::Kitchen.logger).to receive :warn
end

after do
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/kitchen/terraform/verify_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
subject do
described_class.new(
config: config,
logger: logger,
logger: ::Kitchen.logger,
version_requirement: version_requirement,
)
end
Expand Down
1 change: 0 additions & 1 deletion spec/lib/kitchen/transport/terraform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
::Kitchen::Instance.new(
driver: ::Kitchen::Driver::Base.new,
lifecycle_hooks: ::Kitchen::LifecycleHooks.new(config, state_file),
logger: logger,
platform: ::Kitchen::Platform.new(name: "test-platform"),
provisioner: ::Kitchen::Provisioner::Base.new,
state_file: state_file,
Expand Down
1 change: 0 additions & 1 deletion spec/lib/kitchen/verifier/terraform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
::Kitchen::Instance.new(
driver: ::Kitchen::Driver::Base.new,
lifecycle_hooks: ::Kitchen::LifecycleHooks.new(config, state_file),
logger: logger,
platform: ::Kitchen::Platform.new(name: "test-platform"),
provisioner: ::Kitchen::Provisioner::Base.new,
state_file: state_file,
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
expect_configuration.max_formatted_output_length = nil
end

configuration.fail_fast = true
configuration.fail_fast = false

configuration.mock_with :rspec do |mocks|
mocks.verify_doubled_constant_names = true
Expand Down
4 changes: 2 additions & 2 deletions spec/support/kitchen/logger_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
require "kitchen/logger"

::RSpec.shared_context "Kitchen::Logger" do
let :logger do
::Kitchen::Logger.new stdout: ::File.open(::File::NULL, "w")
before do
::Kitchen.logger = ::Kitchen::Logger.new stdout: ::File.open(::File::NULL, "w")
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@

context "when the configured client does exist and is executable" do
let :value do
$0
file = ::Tempfile.new ["client", ".exe"]
file.chmod 0777

file
end

specify "should return false" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require "support/kitchen/logger_context"

::RSpec.shared_examples "Kitchen::Terraform::ConfigAttribute::Systems" do
subject do
described_class.new config
end

include_context "Kitchen::Logger"

let :config do
{
kitchen_root: "kitchen_root",
Expand Down Expand Up @@ -50,7 +54,10 @@

context "when the configured systems are not empty" do
before do
config.store :systems, [::Kitchen::Terraform::System.new(configuration_attributes: {}, logger: logger)]
config.store(
:systems,
[::Kitchen::Terraform::System.new(configuration_attributes: {}, logger: ::Kitchen.logger)]
)
end

specify "should return false" do
Expand Down

0 comments on commit 260e864

Please sign in to comment.