Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
vegaaz authored Mar 1, 2023
2 parents 7238bd5 + ca30099 commit d0582b0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/facter/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def interfaces
confine { Facter::Core::Execution.which('docker') }
setcode do
docker_version = Facter.value(:docker_client_version)
if docker_version&.match?(%r{1[0-9][0-2]?[.]\w+})
if docker_version&.match?(%r{\A(1\.1[3-9]|[2-9]|\d{2,})\.})
docker_json_str = Facter::Core::Execution.execute(
"#{docker_command} info --format '{{json .}}'", timeout: 90
)
Expand Down
31 changes: 31 additions & 0 deletions spec/unit/lib/facter/docker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,37 @@
end
end

describe 'docker_client_version fact containment' do
[
'0.0.1',
'0.5.12',
'1.12.0',
].each do |docker_client_version|
it "Does not generate a nested fact with legacy version #{docker_client_version}" do
expect(Facter.fact(:docker_client_version)).to receive(:value).and_return(docker_client_version)
expect(Facter::Core::Execution).not_to receive(:execute).with("#{docker_command} info --format '{{json .}}'", any_args)

expect(Facter.fact(:docker).value).to be_nil
end
end

[
'1.13.0',
'1.14.0',
'2.0.0',
'20.10.22',
'23.0.1',
'108.42.1',
].each do |docker_client_version|
it "Generates a nested fact with version #{docker_client_version}" do
expect(Facter.fact(:docker_client_version)).to receive(:value).and_return(docker_client_version)
expect(Facter::Core::Execution).to receive(:execute).with("#{docker_command} info --format '{{json .}}'", any_args).and_return('{}')

expect(Facter.fact(:docker).value).not_to be_nil
end
end
end

describe 'docker server version' do
before(:each) do
docker_version = File.read(fixtures('facts', 'docker_version'))
Expand Down

0 comments on commit d0582b0

Please sign in to comment.