From 82d2fe4bf653f8f1363bdb1fe123f5edd81029a7 Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Tue, 4 Oct 2022 16:08:34 -0700 Subject: [PATCH 1/4] (FACT-3154) Adds Ruby 3.2 to rspec tests In preparation for Puppet 8, which will likely use Ruby 3.2, this commit adds Ruby 3.2.0-preview2 to the rspec test matrix. --- .github/workflows/unit_tests.yaml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit_tests.yaml b/.github/workflows/unit_tests.yaml index 64b1e3e03d..d80f42a215 100644 --- a/.github/workflows/unit_tests.yaml +++ b/.github/workflows/unit_tests.yaml @@ -21,7 +21,7 @@ jobs: - '2.3' - '2.7' - '3.0' - - '3.1' + - '3.2.0-preview2' - 'jruby-9.3.7.0' runs-on: ubuntu-latest steps: @@ -38,6 +38,12 @@ jobs: - run: bundle exec rake spec_integration windows_unit_tests: + name: Windows tests with Ruby ${{ matrix.ruby }} + strategy: + matrix: + ruby: + - '2.7' + - '3.1' runs-on: windows-2019 steps: - name: Checkout current PR @@ -46,7 +52,7 @@ jobs: - name: Rspec checks uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7 + ruby-version: ${{ matrix.ruby }} - run: gem update bundler - run: bundle install --jobs 3 --retry 3 - run: bundle exec rake spec_random From 3357ca56aca9795b432c62082ff292260a893fc3 Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Tue, 4 Oct 2022 16:25:35 -0700 Subject: [PATCH 2/4] (FACT-3154) Updates File.exist? method The File.exists? method was deprecated in Ruby 2.1.0: https://github.com/ruby/ruby/blob/6d728bdae9de565ad9d0b2fee2d4c2a33c6f4eac/file.c#L1414 And removed entirely from 3.2.0 onward: https://bugs.ruby-lang.org/issues/17391 This commit updates that method to File.exist? in the directory loader spec tests. --- spec/custom_facts/util/directory_loader_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/custom_facts/util/directory_loader_spec.rb b/spec/custom_facts/util/directory_loader_spec.rb index 3f01fb77a1..bb1d5e4f3d 100755 --- a/spec/custom_facts/util/directory_loader_spec.rb +++ b/spec/custom_facts/util/directory_loader_spec.rb @@ -16,7 +16,7 @@ it "does nothing bad when dir doesn't exist" do fakepath = '/foobar/path' my_loader = LegacyFacter::Util::DirectoryLoader.new(fakepath) - allow(FileTest).to receive(:exists?).with(my_loader.directories[0]).and_return(false) + allow(FileTest).to receive(:exist?).with(my_loader.directories[0]).and_return(false) expect { my_loader.load(collection) }.not_to raise_error end From 24917887a8bf588001bef667b8c2188cfad1c112 Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Thu, 6 Oct 2022 13:45:45 -0700 Subject: [PATCH 3/4] (FACT-3154) Updates socket parser error handling Prior to this commit, the `mac_from` method would implicitly return a logging object when rescuing an error when it should return nil. This commit updates the method to correctly return nil when rescuing an error, which fixes some failing tests in Ruby >= 3.2.0. --- lib/facter/util/linux/socket_parser.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/facter/util/linux/socket_parser.rb b/lib/facter/util/linux/socket_parser.rb index c4b7b4ccef..c7fd6b2ea5 100644 --- a/lib/facter/util/linux/socket_parser.rb +++ b/lib/facter/util/linux/socket_parser.rb @@ -88,6 +88,7 @@ def mac_from(ifaddr) end rescue StandardError => e @log.debug("Could not read mac for interface #{ifaddr.name}, got #{e}") + nil end def mac_from_sockaddr_of(ifaddr) From 2c5e35f5a8aebf7ed6441924ab4911ada8d62b8c Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Thu, 6 Oct 2022 14:00:09 -0700 Subject: [PATCH 4/4] (FACT-3154) Skip YAML parser date spec on Ruby 3.2 There is a bug in timecop in how it interacts with newer versions of Psych that causes our YAML parser date spec to fail. This commit sets this test as pending until we can find a long- term resolution. https://github.com/travisjeffery/timecop/issues/390 --- spec/custom_facts/util/parser_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/custom_facts/util/parser_spec.rb b/spec/custom_facts/util/parser_spec.rb index c45df76fca..e634b00251 100755 --- a/spec/custom_facts/util/parser_spec.rb +++ b/spec/custom_facts/util/parser_spec.rb @@ -354,6 +354,7 @@ def expects_to_parse_powershell(cmd, result) let(:yaml_content) { load_fixture('external_fact_yaml_date').read } it 'loads date' do + pending 'There is a bug in newer versions of Psych and Timecop' if RUBY_VERSION =~ /^3\.2/ expected_result = { 'testsfact' => { 'date' => Date.parse('2020-04-28') } } expect(yaml_parser.parse_results).to eq(expected_result)