summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-03-23 15:06:48 -0700
committerTim Smith <tsmith84@gmail.com>2020-03-23 15:06:48 -0700
commit198913c4676a00ceb31c6d752d54705c8599d96f (patch)
treec108637b2a0e4c6d7861df0cc59d1824f93e4c16
parent77a4e649f337cc10ea26866636b77c683ba84f42 (diff)
downloadchef-cron_validations.tar.gz
Make this a helper module not a mixincron_validations
Stop abusing the mixin name and stop using the mixin like the kitchen drawer of junk it's becoming. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/cron.rb10
-rw-r--r--lib/chef/resource/cron_d.rb12
-rw-r--r--lib/chef/resource/helpers/cron_validations.rb (renamed from lib/chef/mixin/cron_validations.rb)2
-rw-r--r--spec/unit/resource/helpers/cron_validations_spec.rb (renamed from spec/unit/mixin/cron_validations_spec.rb)30
4 files changed, 27 insertions, 27 deletions
diff --git a/lib/chef/resource/cron.rb b/lib/chef/resource/cron.rb
index afb8b627be..d010cfc9bf 100644
--- a/lib/chef/resource/cron.rb
+++ b/lib/chef/resource/cron.rb
@@ -18,7 +18,7 @@
#
require_relative "../resource"
-require_relative "../mixin/cron_validations"
+require_relative "helpers/cron_validations"
require_relative "../provider/cron" # do not remove. we actually need this below
class Chef
@@ -43,25 +43,25 @@ class Chef
property :minute, [Integer, String],
description: "The minute at which the cron entry should run (0 - 59).",
default: "*", callbacks: {
- "should be a valid minute spec" => ->(spec) { Chef::Mixin::CronValidations.validate_numeric(spec, 0, 59) },
+ "should be a valid minute spec" => ->(spec) { Chef::ResourceHelpers::CronValidations.validate_numeric(spec, 0, 59) },
}
property :hour, [Integer, String],
description: "The hour at which the cron entry is to run (0 - 23).",
default: "*", callbacks: {
- "should be a valid hour spec" => ->(spec) { Chef::Mixin::CronValidations.validate_numeric(spec, 0, 23) },
+ "should be a valid hour spec" => ->(spec) { Chef::ResourceHelpers::CronValidations.validate_numeric(spec, 0, 23) },
}
property :day, [Integer, String],
description: "The day of month at which the cron entry should run (1 - 31).",
default: "*", callbacks: {
- "should be a valid day spec" => ->(spec) { Chef::Mixin::CronValidations.validate_numeric(spec, 1, 31) },
+ "should be a valid day spec" => ->(spec) { Chef::ResourceHelpers::CronValidations.validate_numeric(spec, 1, 31) },
}
property :month, [Integer, String],
description: "The month in the year on which a cron entry is to run (1 - 12, jan-dec, or *).",
default: "*", callbacks: {
- "should be a valid month spec" => ->(spec) { Chef::Mixin::CronValidations.validate_month(spec) },
+ "should be a valid month spec" => ->(spec) { Chef::ResourceHelpers::CronValidations.validate_month(spec) },
}
def weekday(arg = nil)
diff --git a/lib/chef/resource/cron_d.rb b/lib/chef/resource/cron_d.rb
index 98e962ac66..e440b8341b 100644
--- a/lib/chef/resource/cron_d.rb
+++ b/lib/chef/resource/cron_d.rb
@@ -16,7 +16,7 @@
#
require_relative "../resource"
-require_relative "../mixin/cron_validations"
+require_relative "helpers/cron_validations"
require "shellwords" unless defined?(Shellwords)
require_relative "../dist"
@@ -87,31 +87,31 @@ class Chef
property :minute, [Integer, String],
description: "The minute at which the cron entry should run (0 - 59).",
default: "*", callbacks: {
- "should be a valid minute spec" => ->(spec) { Chef::Mixin::CronValidations.validate_numeric(spec, 0, 59) },
+ "should be a valid minute spec" => ->(spec) { Chef::ResourceHelpers::CronValidations.validate_numeric(spec, 0, 59) },
}
property :hour, [Integer, String],
description: "The hour at which the cron entry is to run (0 - 23).",
default: "*", callbacks: {
- "should be a valid hour spec" => ->(spec) { Chef::Mixin::CronValidations.validate_numeric(spec, 0, 23) },
+ "should be a valid hour spec" => ->(spec) { Chef::ResourceHelpers::CronValidations.validate_numeric(spec, 0, 23) },
}
property :day, [Integer, String],
description: "The day of month at which the cron entry should run (1 - 31).",
default: "*", callbacks: {
- "should be a valid day spec" => ->(spec) { Chef::Mixin::CronValidations.validate_numeric(spec, 1, 31) },
+ "should be a valid day spec" => ->(spec) { Chef::ResourceHelpers::CronValidations.validate_numeric(spec, 1, 31) },
}
property :month, [Integer, String],
description: "The month in the year on which a cron entry is to run (1 - 12, jan-dec, or *).",
default: "*", callbacks: {
- "should be a valid month spec" => ->(spec) { Chef::Mixin::CronValidations.validate_month(spec) },
+ "should be a valid month spec" => ->(spec) { Chef::ResourceHelpers::CronValidations.validate_month(spec) },
}
property :weekday, [Integer, String],
description: "The day of the week on which this entry is to run (0-7, mon-sun, or *), where Sunday is both 0 and 7.",
default: "*", callbacks: {
- "should be a valid weekday spec" => ->(spec) { Chef::Mixin::CronValidations.validate_dow(spec) },
+ "should be a valid weekday spec" => ->(spec) { Chef::ResourceHelpers::CronValidations.validate_dow(spec) },
}
property :command, String,
diff --git a/lib/chef/mixin/cron_validations.rb b/lib/chef/resource/helpers/cron_validations.rb
index 8428624dc2..d09113d64c 100644
--- a/lib/chef/mixin/cron_validations.rb
+++ b/lib/chef/resource/helpers/cron_validations.rb
@@ -16,7 +16,7 @@
#
class Chef
- module Mixin
+ module ResourceHelpers
# a collection of methods for validating cron times. Used in the various cron-like resources
module CronValidations
# validate a provided value is between two other provided values
diff --git a/spec/unit/mixin/cron_validations_spec.rb b/spec/unit/resource/helpers/cron_validations_spec.rb
index b37a523237..ac5d9e2c58 100644
--- a/spec/unit/mixin/cron_validations_spec.rb
+++ b/spec/unit/resource/helpers/cron_validations_spec.rb
@@ -14,64 +14,64 @@
# limitations under the License.
require "spec_helper"
-require "chef/mixin/cron_validations"
+require "chef/resource/helpers/cron_validations"
-describe Chef::Mixin::CronValidations do
+describe Chef::ResourceHelpers::CronValidations do
context "#validate_dow" do
it "it accepts a string day" do
- expect(Chef::Mixin::CronValidations.validate_dow("mon")).to be true
+ expect(Chef::ResourceHelpers::CronValidations.validate_dow("mon")).to be true
end
it "it accepts an integer day" do
- expect(Chef::Mixin::CronValidations.validate_dow(0)).to be true
+ expect(Chef::ResourceHelpers::CronValidations.validate_dow(0)).to be true
end
it "it accepts the string of *" do
- expect(Chef::Mixin::CronValidations.validate_dow("*")).to be true
+ expect(Chef::ResourceHelpers::CronValidations.validate_dow("*")).to be true
end
it "returns false for an out of range integer" do
- expect(Chef::Mixin::CronValidations.validate_dow(8)).to be false
+ expect(Chef::ResourceHelpers::CronValidations.validate_dow(8)).to be false
end
it "returns false for an invalid string" do
- expect(Chef::Mixin::CronValidations.validate_dow("monday")).to be false
+ expect(Chef::ResourceHelpers::CronValidations.validate_dow("monday")).to be false
end
end
context "#validate_month" do
it "it accepts a string month" do
- expect(Chef::Mixin::CronValidations.validate_month("feb")).to be true
+ expect(Chef::ResourceHelpers::CronValidations.validate_month("feb")).to be true
end
it "it accepts an integer month" do
- expect(Chef::Mixin::CronValidations.validate_month(2)).to be true
+ expect(Chef::ResourceHelpers::CronValidations.validate_month(2)).to be true
end
it "it accepts the string of *" do
- expect(Chef::Mixin::CronValidations.validate_month("*")).to be true
+ expect(Chef::ResourceHelpers::CronValidations.validate_month("*")).to be true
end
it "returns false for an out of range integer" do
- expect(Chef::Mixin::CronValidations.validate_month(13)).to be false
+ expect(Chef::ResourceHelpers::CronValidations.validate_month(13)).to be false
end
it "returns false for an invalid string (typo)" do
- expect(Chef::Mixin::CronValidations.validate_month("janurary")).to be false
+ expect(Chef::ResourceHelpers::CronValidations.validate_month("janurary")).to be false
end
end
context "#validate_numeric" do
it "returns true if the value is in the allowed range" do
- expect(Chef::Mixin::CronValidations.validate_numeric(5, 1, 100)).to be true
+ expect(Chef::ResourceHelpers::CronValidations.validate_numeric(5, 1, 100)).to be true
end
it "returns false if the value less than the allowed range" do
- expect(Chef::Mixin::CronValidations.validate_numeric(-1, 1, 100)).to be false
+ expect(Chef::ResourceHelpers::CronValidations.validate_numeric(-1, 1, 100)).to be false
end
it "returns false if the value more than the allowed range" do
- expect(Chef::Mixin::CronValidations.validate_numeric(101, 1, 100)).to be false
+ expect(Chef::ResourceHelpers::CronValidations.validate_numeric(101, 1, 100)).to be false
end
end
end