diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-04-15 18:28:21 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-04-15 18:28:21 -0700 |
commit | 1055333ac4d4912ac671bca07bc3cd430cd2ef64 (patch) | |
tree | 3a8f1e6e55ca6a1a851ee51bd9540c0db6de88ab | |
parent | 8dd7e3dce2a91c4dcdada2f4adf26f51a4ed2e71 (diff) | |
download | chef-1055333ac4d4912ac671bca07bc3cd430cd2ef64.tar.gz |
Simplify the logic + improve the spec
Use 2006 as the base year. Chef 15 goes EOL next year on 5-1-2021 so
2006 + 15 = 2021 and then we know it.
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/client.rb | 13 | ||||
-rw-r--r-- | spec/unit/client_spec.rb | 6 |
2 files changed, 8 insertions, 11 deletions
diff --git a/lib/chef/client.rb b/lib/chef/client.rb index 4985d6ea1d..769d1a4989 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -329,15 +329,12 @@ class Chef def warn_if_eol require_relative "version" - # we have a yearly release and we know 15 goes EOL in 2021 so calculate off that - # this way we don't have to update anything or maintain a hash of EOL dates - base_eol_year = 2022 - base_release = Gem::Version.new(15) + # We make a release every year so take the version you're on + 2006 and you get + # the year it goes EOL + eol_year = 2006 + Gem::Version.new(Chef::VERSION).segments.first - diff_from_base_release = Gem::Version.new(Chef::VERSION).segments.first - base_release.segments.first - - if Time.now > Time.new(base_eol_year + diff_from_base_release, 5, 1) - logger.warn("This release of #{Chef::Dist::PRODUCT} became end of life (EOL) on May 1st #{base_eol_year + diff_from_base_release}. Please update to a supported release to receive new features, bug fixes, and security updates.") + if Time.now > Time.new(eol_year, 5, 01) + logger.warn("This release of #{Chef::Dist::PRODUCT} became end of life (EOL) on May 1st #{eol_year}. Please update to a supported release to receive new features, bug fixes, and security updates.") end end diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index d7b58b580f..8553c52b79 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -310,14 +310,14 @@ describe Chef::Client do describe "eol release warning" do it "warns when running an EOL release" do stub_const("Chef::VERSION", 15) - allow(Time).to receive(:now).and_return(Time.new("2030-01-01")) - expect(logger).to receive(:warn).with(/This release of.*became end of life \(EOL\) on May 1st 2022/) + allow(Time).to receive(:now).and_return(Time.new(2021, 5, 1, 5)) + expect(logger).to receive(:warn).with(/This release of.*became end of life \(EOL\) on May 1st 2021/) client.warn_if_eol end it "does not warn when running an non-EOL release" do stub_const("Chef::VERSION", 15) - allow(Time).to receive(:now).and_return(Time.new("2020-01-01")) + allow(Time).to receive(:now).and_return(Time.new(2021, 4, 31)) expect(logger).to_not receive(:warn).with(/became end of life/) client.warn_if_eol end |