diff --git a/lib/facter/docker.rb b/lib/facter/docker.rb index a8d33ad6..a8d7e87e 100644 --- a/lib/facter/docker.rb +++ b/lib/facter/docker.rb @@ -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 ) diff --git a/spec/unit/lib/facter/docker_spec.rb b/spec/unit/lib/facter/docker_spec.rb index 7e2d600b..022d061d 100644 --- a/spec/unit/lib/facter/docker_spec.rb +++ b/spec/unit/lib/facter/docker_spec.rb @@ -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'))