kitchen-docker 2.15.0 → 3.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CODEOWNERS +1 -0
  3. data/.github/workflows/lint.yml +99 -0
  4. data/.github/workflows/publish.yaml +32 -0
  5. data/.gitignore +1 -0
  6. data/.markdownlint.yaml +6 -0
  7. data/.release-please-manifest.json +3 -0
  8. data/.rubocop.yml +9 -0
  9. data/.yamllint +15 -0
  10. data/CHANGELOG.md +40 -0
  11. data/Gemfile +20 -1
  12. data/README.md +16 -9
  13. data/Rakefile +13 -36
  14. data/cookbooks +1 -0
  15. data/kitchen-docker.gemspec +9 -29
  16. data/kitchen.windows.yml +31 -0
  17. data/kitchen.yml +94 -0
  18. data/lib/kitchen/docker/container/linux.rb +17 -17
  19. data/lib/kitchen/docker/container/windows.rb +11 -11
  20. data/lib/kitchen/docker/container.rb +7 -7
  21. data/lib/kitchen/docker/docker_version.rb +1 -1
  22. data/lib/kitchen/docker/erb_context.rb +3 -3
  23. data/lib/kitchen/docker/helpers/cli_helper.rb +184 -172
  24. data/lib/kitchen/docker/helpers/container_helper.rb +178 -172
  25. data/lib/kitchen/docker/helpers/dockerfile_helper.rb +34 -34
  26. data/lib/kitchen/docker/helpers/file_helper.rb +4 -4
  27. data/lib/kitchen/docker/helpers/image_helper.rb +28 -14
  28. data/lib/kitchen/docker/helpers/inspec_helper.rb +62 -40
  29. data/lib/kitchen/driver/docker.rb +34 -40
  30. data/lib/kitchen/transport/docker.rb +15 -16
  31. data/release-please-config.json +12 -0
  32. data/renovate.json +8 -0
  33. data/spec/docker_spec.rb +108 -0
  34. data/spec/dockerfile_helper_spec.rb +109 -0
  35. data/spec/inspec_helper_spec.rb +58 -0
  36. data/{test/spec → spec}/spec_helper.rb +5 -26
  37. data/test/Dockerfile +4 -5
  38. data/test/cookbooks/cinc_test/metadata.rb +2 -0
  39. data/test/cookbooks/cinc_test/recipes/default.rb +10 -0
  40. data/test/cookbooks/docker_test/attributes/default.rb +1 -0
  41. data/test/cookbooks/docker_test/metadata.rb +3 -0
  42. data/test/cookbooks/docker_test/recipes/default.rb +94 -0
  43. data/test/integration/capabilities/{serverspec → disabled}/capabilities_drop_spec.rb +7 -6
  44. data/test/integration/cinc/inspec/cinc_spec.rb +21 -0
  45. data/test/integration/default/{serverspec → disabled}/default_spec.rb +7 -6
  46. data/test/integration/default/{serverspec → disabled}/spec_helper.rb +7 -7
  47. data/test/integration/inspec/inspec_spec.rb +3 -3
  48. metadata +33 -202
  49. data/.cane +0 -0
  50. data/.github/dependabot.yml +0 -7
  51. data/.kitchen.windows.yml +0 -33
  52. data/.kitchen.yml +0 -65
  53. data/.tailor +0 -4
  54. data/.travis.yml +0 -57
  55. data/lib/docker/version.rb +0 -25
  56. data/lib/train/docker.rb +0 -125
  57. data/test/spec/docker_spec.rb +0 -64
@@ -1,40 +1,62 @@
1
- #
2
- # Licensed under the Apache License, Version 2.0 (the "License");
3
- # you may not use this file except in compliance with the License.
4
- # You may obtain a copy of the License at
5
- #
6
- # http://www.apache.org/licenses/LICENSE-2.0
7
- #
8
- # Unless required by applicable law or agreed to in writing, software
9
- # distributed under the License is distributed on an "AS IS" BASIS,
10
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- # See the License for the specific language governing permissions and
12
- # limitations under the License.
13
-
14
- # This helper should be removed when the kitchen-inspec gem has been updated to include these runner options
15
- begin
16
- require 'kitchen/verifier/inspec'
17
-
18
- # Add runner options for Docker transport for kitchen-inspec gem
19
- module Kitchen
20
- module Docker
21
- module Helpers
22
- module InspecHelper
23
- Kitchen::Verifier::Inspec.class_eval do
24
- def runner_options_for_docker(config_data)
25
- opts = {
26
- 'backend' => 'docker',
27
- 'logger' => logger,
28
- 'host' => config_data[:container_id],
29
- }
30
- logger.debug "Connect to Container: #{opts['host']}"
31
- opts
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
38
- rescue LoadError => e
39
- logger.debug("[Docker] kitchen-inspec gem not found for InSpec verifier. #{e}")
40
- end
1
+ #
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+
14
+ # This helper patches kitchen-inspec and/or kitchen-cinc-auditor to add Docker
15
+ # transport support. Remove once upstream gems include this natively.
16
+
17
+ # Patch kitchen-inspec if available
18
+ begin
19
+ require "kitchen/verifier/inspec"
20
+ Kitchen::Verifier::Inspec.class_eval do
21
+ def runner_options_for_docker(config_data)
22
+ opts = {
23
+ "backend" => "docker",
24
+ "logger" => logger,
25
+ "host" => config_data[:container_id],
26
+ }
27
+ logger.debug "Connect to Container: #{opts["host"]}"
28
+ opts
29
+ end
30
+ end
31
+ rescue LoadError
32
+ # kitchen-inspec not available; skipping patch
33
+ end
34
+
35
+ # Patch kitchen-cinc-auditor if available
36
+ begin
37
+ require "kitchen/verifier/cinc_auditor"
38
+ Kitchen::Verifier::CincAuditor::TransportOptions.class_eval do
39
+ def build_docker(state)
40
+ options = {
41
+ "backend" => "docker",
42
+ "logger" => logger,
43
+ "host" => state[:container_id],
44
+ }
45
+ logger.debug("Connect to Container: #{options["host"]}")
46
+ options
47
+ end
48
+ end
49
+ rescue LoadError
50
+ # kitchen-cinc-auditor not available; skipping patch
51
+ end
52
+
53
+ module Kitchen
54
+ module Docker
55
+ module Helpers
56
+ # Marker module included by the Docker transport Connection class.
57
+ # Actual verifier patches are applied directly to verifier classes above.
58
+ module InspecHelper
59
+ end
60
+ end
61
+ end
62
+ end
@@ -13,17 +13,17 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- require 'kitchen'
17
- require 'json'
18
- require 'securerandom'
19
- require 'net/ssh'
16
+ require "kitchen"
17
+ require "json" unless defined?(JSON)
18
+ require "securerandom" unless defined?(SecureRandom)
19
+ require "net/ssh" unless defined?(Net::SSH)
20
20
 
21
- require 'kitchen/driver/base'
21
+ require "kitchen/driver/base"
22
22
 
23
- require_relative '../docker/container/linux'
24
- require_relative '../docker/container/windows'
25
- require_relative '../docker/helpers/cli_helper'
26
- require_relative '../docker/helpers/container_helper'
23
+ require_relative "../docker/container/linux"
24
+ require_relative "../docker/container/windows"
25
+ require_relative "../docker/helpers/cli_helper"
26
+ require_relative "../docker/helpers/container_helper"
27
27
 
28
28
  module Kitchen
29
29
  module Driver
@@ -35,7 +35,7 @@ module Kitchen
35
35
  include Kitchen::Docker::Helpers::ContainerHelper
36
36
  include ShellOut
37
37
 
38
- default_config :binary, 'docker'
38
+ default_config :binary, "docker"
39
39
  default_config :build_options, nil
40
40
  default_config :build_tempdir, Dir.pwd
41
41
  default_config :cap_add, nil
@@ -44,9 +44,9 @@ module Kitchen
44
44
  default_config :env_variables, nil
45
45
  default_config :isolation, nil
46
46
  default_config :interactive, false
47
- default_config :private_key, File.join(Dir.pwd, '.kitchen', 'docker_id_rsa')
47
+ default_config :private_key, File.join(Dir.pwd, ".kitchen", "docker_id_rsa")
48
48
  default_config :privileged, false
49
- default_config :public_key, File.join(Dir.pwd, '.kitchen', 'docker_id_rsa.pub')
49
+ default_config :public_key, File.join(Dir.pwd, ".kitchen", "docker_id_rsa.pub")
50
50
  default_config :publish_all, false
51
51
  default_config :remove_images, false
52
52
  default_config :run_options, nil
@@ -66,43 +66,39 @@ module Kitchen
66
66
  !driver.remote_socket?
67
67
  end
68
68
 
69
- default_config :image do |driver|
70
- driver.default_image
71
- end
69
+ default_config :image, &:default_image
72
70
 
73
71
  default_config :instance_name do |driver|
74
72
  # Borrowed from kitchen-rackspace
75
73
  [
76
- driver.instance.name.gsub(/\W/, ''),
77
- (Etc.getlogin || 'nologin').gsub(/\W/, ''),
78
- Socket.gethostname.gsub(/\W/, '')[0..20],
79
- Array.new(8) { rand(36).to_s(36) }.join
80
- ].join('-').downcase
74
+ driver.instance.name.gsub(/\W/, ""),
75
+ (Etc.getlogin || "nologin").gsub(/\W/, ""),
76
+ Socket.gethostname.gsub(/\W/, "")[0..20],
77
+ Array.new(8) { rand(36).to_s(36) }.join,
78
+ ].join("-").downcase
81
79
  end
82
80
 
83
- default_config :platform do |driver|
84
- driver.default_platform
85
- end
81
+ default_config :platform, &:default_platform
86
82
 
87
83
  default_config :run_command do |driver|
88
84
  if driver.windows_os?
89
85
  # Launch arbitrary process to keep the Windows container alive
90
86
  # If running in interactive mode, launch powershell.exe instead
91
87
  if driver[:interactive]
92
- 'powershell.exe'
88
+ "powershell.exe"
93
89
  else
94
- 'ping -t localhost'
90
+ "ping -t localhost"
95
91
  end
96
92
  else
97
- '/usr/sbin/sshd -D -o UseDNS=no -o UsePAM=no -o PasswordAuthentication=yes '\
98
- '-o UsePrivilegeSeparation=no -o PidFile=/tmp/sshd.pid'
93
+ "/usr/sbin/sshd -D -o UseDNS=no -o UsePAM=no -o PasswordAuthentication=yes " \
94
+ "-o UsePrivilegeSeparation=no -o PidFile=/tmp/sshd.pid"
99
95
  end
100
96
  end
101
97
 
102
98
  default_config :socket do |driver|
103
- socket = 'unix:///var/run/docker.sock'
104
- socket = 'npipe:////./pipe/docker_engine' if driver.windows_os?
105
- ENV['DOCKER_HOST'] || socket
99
+ socket = "unix:///var/run/docker.sock"
100
+ socket = "npipe:////./pipe/docker_engine" if Gem.win_platform?
101
+ ENV["DOCKER_HOST"] || socket
106
102
  end
107
103
 
108
104
  default_config :username do |driver|
@@ -111,14 +107,14 @@ module Kitchen
111
107
  if driver.windows_os?
112
108
  nil
113
109
  else
114
- 'kitchen'
110
+ "kitchen"
115
111
  end
116
112
  end
117
113
 
118
114
  def verify_dependencies
119
115
  run_command("#{config[:binary]} >> #{dev_null} 2>&1", quiet: true, use_sudo: config[:use_sudo])
120
116
  rescue
121
- raise UserError, 'You must first install the Docker CLI tool https://www.docker.com/get-started'
117
+ raise UserError, "You must first install the Docker CLI tool https://www.docker.com/get-started"
122
118
  end
123
119
 
124
120
  def create(state)
@@ -133,22 +129,20 @@ module Kitchen
133
129
 
134
130
  def wait_for_transport(state)
135
131
  if config[:wait_for_transport]
136
- instance.transport.connection(state) do |conn|
137
- conn.wait_until_ready
138
- end
132
+ instance.transport.connection(state, &:wait_until_ready)
139
133
  end
140
134
  end
141
135
 
142
136
  def default_image
143
- platform, release = instance.platform.name.split('-')
144
- if platform == 'centos' && release
145
- release = 'centos' + release.split('.').first
137
+ platform, release = instance.platform.name.split("-")
138
+ if platform == "centos" && release
139
+ release = "centos" + release.split(".").first
146
140
  end
147
- release ? [platform, release].join(':') : platform
141
+ release ? [platform, release].join(":") : platform
148
142
  end
149
143
 
150
144
  def default_platform
151
- instance.platform.name.split('-').first
145
+ instance.platform.name.split("-").first
152
146
  end
153
147
 
154
148
  protected
@@ -11,25 +11,24 @@
11
11
  # See the License for the specific language governing permissions and
12
12
  # limitations under the License.
13
13
 
14
- require 'kitchen'
14
+ require "kitchen"
15
15
 
16
- require_relative '../docker/container/linux'
17
- require_relative '../docker/container/windows'
16
+ require_relative "../docker/container/linux"
17
+ require_relative "../docker/container/windows"
18
18
 
19
- require_relative '../docker/helpers/inspec_helper'
19
+ require_relative "../docker/helpers/inspec_helper"
20
20
 
21
- require_relative '../../docker/version.rb'
22
- require_relative '../../train/docker.rb'
21
+ # require_relative "../../docker/version"
23
22
 
24
23
  module Kitchen
25
24
  module Transport
26
25
  class Docker < Kitchen::Transport::Base
27
26
  class DockerFailed < TransportFailed; end
28
27
 
29
- kitchen_transport_api_version 1
28
+ # kitchen_transport_api_version 1
30
29
  plugin_version Kitchen::VERSION
31
30
 
32
- default_config :binary, 'docker'
31
+ default_config :binary, "docker"
33
32
  default_config :env_variables, nil
34
33
  default_config :interactive, false
35
34
  default_config :privileged, false
@@ -42,16 +41,16 @@ module Kitchen
42
41
  default_config :working_dir, nil
43
42
 
44
43
  default_config :socket do |transport|
45
- socket = 'unix:///var/run/docker.sock'
46
- socket = 'npipe:////./pipe/docker_engine' if transport.windows_os?
47
- ENV['DOCKER_HOST'] || socket
44
+ socket = "unix:///var/run/docker.sock"
45
+ socket = "npipe:////./pipe/docker_engine" if Gem.win_platform?
46
+ ENV["DOCKER_HOST"] || socket
48
47
  end
49
48
 
50
49
  default_config :temp_dir do |transport|
51
50
  if transport.windows_os?
52
- '$env:TEMP'
51
+ "$env:TEMP"
53
52
  else
54
- '/tmp'
53
+ "/tmp"
55
54
  end
56
55
  end
57
56
 
@@ -61,7 +60,7 @@ module Kitchen
61
60
  if transport.windows_os?
62
61
  nil
63
62
  else
64
- 'kitchen'
63
+ "kitchen"
65
64
  end
66
65
  end
67
66
 
@@ -73,7 +72,7 @@ module Kitchen
73
72
  # This allows Windows systems to use the TCP socket for the InSpec verifier
74
73
  # See the lib/docker.rb file here: https://github.com/swipely/docker-api/blob/master/lib/docker.rb
75
74
  # default_socket_url is set to a Unix socket and env_url requires an environment variable to be set
76
- ENV['DOCKER_HOST'] = options[:socket] if !options[:socket].nil? && ENV['DOCKER_HOST'].nil?
75
+ ENV["DOCKER_HOST"] = options[:socket] if !options[:socket].nil? && ENV["DOCKER_HOST"].nil?
77
76
 
78
77
  Kitchen::Transport::Docker::Connection.new(options, &block)
79
78
  end
@@ -98,7 +97,7 @@ module Kitchen
98
97
  end
99
98
 
100
99
  def container
101
- @container ||= if @options[:platform].include?('windows')
100
+ @container ||= if @options[:platform].include?("windows")
102
101
  Kitchen::Docker::Container::Windows.new(@options)
103
102
  else
104
103
  Kitchen::Docker::Container::Linux.new(@options)
@@ -0,0 +1,12 @@
1
+ {
2
+ "packages": {
3
+ ".": {
4
+ "package-name": "kitchen-docker",
5
+ "changelog-path": "CHANGELOG.md",
6
+ "release-type": "ruby",
7
+ "include-component-in-tag": false,
8
+ "version-file": "lib/kitchen/docker/docker_version.rb"
9
+ }
10
+ },
11
+ "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
12
+ }
data/renovate.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "extends": [
4
+ "config:recommended",
5
+ ":disableDependencyDashboard",
6
+ "schedule:automergeEarlyMondays"
7
+ ]
8
+ }
@@ -0,0 +1,108 @@
1
+ #
2
+ # Copyright 2016, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require "spec_helper"
18
+
19
+ describe Kitchen::Driver::Docker do
20
+ describe "#config_to_options" do
21
+ let(:config) {}
22
+ subject { described_class.new.send(:config_to_options, config) }
23
+
24
+ context "with nil" do
25
+ let(:config) { nil }
26
+ it { is_expected.to eq "" }
27
+ end # /context with nil
28
+
29
+ context "with a string" do
30
+ let(:config) { "--foo" }
31
+ it { is_expected.to eq "--foo" }
32
+ end # /context with a string
33
+
34
+ context "with a string with spaces" do
35
+ let(:config) { "--foo bar" }
36
+ it { is_expected.to eq "--foo bar" }
37
+ end # /context with a string with spaces
38
+
39
+ context "with an array of strings" do
40
+ let(:config) { %w{--foo --bar} }
41
+ it { is_expected.to eq "--foo --bar" }
42
+ end # /context with an array of strings
43
+
44
+ context "with an array of hashes" do
45
+ let(:config) { [{ foo: "bar" }, { other: "baz" }] }
46
+ it { is_expected.to eq "--foo=bar --other=baz" }
47
+ end # /context with an array of hashes
48
+
49
+ context "with a hash of strings" do
50
+ let(:config) { { foo: "bar", other: "baz" } }
51
+ it { is_expected.to eq "--foo=bar --other=baz" }
52
+ end # /context with a hash of strings
53
+
54
+ context "with a hash of arrays" do
55
+ let(:config) { { foo: %w{bar baz} } }
56
+ it { is_expected.to eq "--foo=bar --foo=baz" }
57
+ end # /context with a hash of arrays
58
+
59
+ context "with a hash of strings with spaces" do
60
+ let(:config) { { foo: "bar two", other: "baz" } }
61
+ it { is_expected.to eq '--foo=bar\\ two --other=baz' }
62
+ end # /context with a hash of strings with spaces
63
+ end # /describe #config_to_options
64
+
65
+ describe "socket default config logic" do
66
+ def resolve_socket
67
+ socket = "unix:///var/run/docker.sock"
68
+ socket = "npipe:////./pipe/docker_engine" if Gem.win_platform?
69
+ ENV["DOCKER_HOST"] || socket
70
+ end
71
+
72
+ context "on a non-Windows host without DOCKER_HOST set" do
73
+ before do
74
+ allow(Gem).to receive(:win_platform?).and_return(false)
75
+ allow(ENV).to receive(:[]).and_call_original
76
+ allow(ENV).to receive(:[]).with("DOCKER_HOST").and_return(nil)
77
+ end
78
+
79
+ it "uses the Unix socket" do
80
+ expect(resolve_socket).to eq("unix:///var/run/docker.sock")
81
+ end
82
+ end
83
+
84
+ context "on a Windows host without DOCKER_HOST set" do
85
+ before do
86
+ allow(Gem).to receive(:win_platform?).and_return(true)
87
+ allow(ENV).to receive(:[]).and_call_original
88
+ allow(ENV).to receive(:[]).with("DOCKER_HOST").and_return(nil)
89
+ end
90
+
91
+ it "uses the Windows named pipe" do
92
+ expect(resolve_socket).to eq("npipe:////./pipe/docker_engine")
93
+ end
94
+ end
95
+
96
+ context "when DOCKER_HOST env var is set" do
97
+ before do
98
+ allow(Gem).to receive(:win_platform?).and_return(false)
99
+ allow(ENV).to receive(:[]).and_call_original
100
+ allow(ENV).to receive(:[]).with("DOCKER_HOST").and_return("tcp://192.168.1.1:2375")
101
+ end
102
+
103
+ it "uses DOCKER_HOST over the default socket" do
104
+ expect(resolve_socket).to eq("tcp://192.168.1.1:2375")
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,109 @@
1
+ #
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ #
14
+
15
+ require "spec_helper"
16
+ require "kitchen/docker/helpers/dockerfile_helper"
17
+
18
+ describe Kitchen::Docker::Helpers::DockerfileHelper do
19
+ let(:helper_class) do
20
+ Class.new do
21
+ include Kitchen::Docker::Helpers::DockerfileHelper
22
+ attr_accessor :config
23
+
24
+ def initialize(config = {})
25
+ @config = config
26
+ end
27
+ end
28
+ end
29
+
30
+ let(:helper) { helper_class.new(platform:) }
31
+
32
+ describe "#amazonlinux_platform" do
33
+ let(:platform) { "amazonlinux" }
34
+
35
+ it "includes --allowerasing flag for yum install" do
36
+ result = helper.amazonlinux_platform
37
+ expect(result).to include("yum install -y --allowerasing")
38
+ end
39
+
40
+ it "installs required packages including curl" do
41
+ result = helper.amazonlinux_platform
42
+ expect(result).to include("sudo openssh-server openssh-clients which curl")
43
+ end
44
+
45
+ it "sets container environment variable" do
46
+ result = helper.amazonlinux_platform
47
+ expect(result).to include("ENV container=docker")
48
+ end
49
+
50
+ it "generates SSH host key if missing" do
51
+ result = helper.amazonlinux_platform
52
+ expect(result).to include("ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key")
53
+ end
54
+ end
55
+
56
+ describe "#rhel_platform" do
57
+ let(:platform) { "rhel" }
58
+
59
+ it "does not include --allowerasing flag" do
60
+ result = helper.rhel_platform
61
+ expect(result).not_to include("--allowerasing")
62
+ end
63
+
64
+ it "installs required packages including curl" do
65
+ result = helper.rhel_platform
66
+ expect(result).to include("sudo openssh-server openssh-clients which curl")
67
+ end
68
+ end
69
+
70
+ describe "#dockerfile_platform" do
71
+ context "when platform is amazonlinux" do
72
+ let(:platform) { "amazonlinux" }
73
+
74
+ it "calls amazonlinux_platform method" do
75
+ expect(helper).to receive(:amazonlinux_platform).and_call_original
76
+ result = helper.dockerfile_platform
77
+ expect(result).to include("--allowerasing")
78
+ end
79
+ end
80
+
81
+ context "when platform is rhel" do
82
+ let(:platform) { "rhel" }
83
+
84
+ it "calls rhel_platform method" do
85
+ expect(helper).to receive(:rhel_platform).and_call_original
86
+ result = helper.dockerfile_platform
87
+ expect(result).not_to include("--allowerasing")
88
+ end
89
+ end
90
+
91
+ context "when platform is centos" do
92
+ let(:platform) { "centos" }
93
+
94
+ it "calls rhel_platform method" do
95
+ expect(helper).to receive(:rhel_platform).and_call_original
96
+ helper.dockerfile_platform
97
+ end
98
+ end
99
+
100
+ context "when platform is oraclelinux" do
101
+ let(:platform) { "oraclelinux" }
102
+
103
+ it "calls rhel_platform method" do
104
+ expect(helper).to receive(:rhel_platform).and_call_original
105
+ helper.dockerfile_platform
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,58 @@
1
+ require "spec_helper"
2
+ require "logger"
3
+
4
+ RSpec.describe "inspec_helper patches" do
5
+ let(:helper_path) { File.expand_path("../lib/kitchen/docker/helpers/inspec_helper.rb", __dir__) }
6
+
7
+ describe "kitchen-inspec patch" do
8
+ # Test actual post-load state rather than trying to stub Kernel.require,
9
+ # which does not intercept require calls made inside a load'd file in Ruby 3.4.
10
+ if defined?(Kitchen::Verifier::Inspec)
11
+ it "adds runner_options_for_docker to Kitchen::Verifier::Inspec" do
12
+ expect(Kitchen::Verifier::Inspec.method_defined?(:runner_options_for_docker)).to be true
13
+ end
14
+ else
15
+ it "Kitchen::Verifier::Inspec not available — patch correctly skipped" do
16
+ expect(defined?(Kitchen::Verifier::Inspec)).to be_falsy
17
+ end
18
+ end
19
+
20
+ context "when kitchen-inspec is not available" do
21
+ before do
22
+ allow(Kernel).to receive(:require).and_call_original
23
+ allow(Kernel).to receive(:require).with("kitchen/verifier/inspec").and_raise(LoadError)
24
+ allow(Kernel).to receive(:require).with("kitchen/verifier/cinc_auditor").and_raise(LoadError)
25
+ end
26
+
27
+ it "does not raise when loading the helper" do
28
+ expect { load helper_path }.not_to raise_error
29
+ end
30
+ end
31
+ end
32
+
33
+ describe "kitchen-cinc-auditor patch" do
34
+ # Test actual post-load state rather than trying to stub Kernel.require.
35
+ if defined?(Kitchen::Verifier::CincAuditor) &&
36
+ defined?(Kitchen::Verifier::CincAuditor::TransportOptions)
37
+ it "adds build_docker to Kitchen::Verifier::CincAuditor::TransportOptions" do
38
+ expect(Kitchen::Verifier::CincAuditor::TransportOptions.method_defined?(:build_docker)).to be true
39
+ end
40
+ else
41
+ it "Kitchen::Verifier::CincAuditor not available — patch correctly skipped" do
42
+ expect(defined?(Kitchen::Verifier::CincAuditor)).to be_falsy
43
+ end
44
+ end
45
+
46
+ context "when kitchen-cinc-auditor is not available" do
47
+ before do
48
+ allow(Kernel).to receive(:require).and_call_original
49
+ allow(Kernel).to receive(:require).with("kitchen/verifier/inspec").and_raise(LoadError)
50
+ allow(Kernel).to receive(:require).with("kitchen/verifier/cinc_auditor").and_raise(LoadError)
51
+ end
52
+
53
+ it "does not raise when loading the helper" do
54
+ expect { load helper_path }.not_to raise_error
55
+ end
56
+ end
57
+ end
58
+ end