Remove VALID_FEATURES constant

This commit is contained in:
Brian Cain 2018-12-07 13:52:02 -08:00
parent accabdd7ca
commit 2783b121f9
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
4 changed files with 2 additions and 55 deletions

View File

@ -174,11 +174,6 @@ begin
ui.warn(I18n.t("vagrant.general.experimental.all"), bold: true, prefix: true, channel: :error) ui.warn(I18n.t("vagrant.general.experimental.all"), bold: true, prefix: true, channel: :error)
else else
ui.warn(I18n.t("vagrant.general.experimental.features", features: experimental.join(", ")), bold: true, prefix: true, channel: :error) ui.warn(I18n.t("vagrant.general.experimental.features", features: experimental.join(", ")), bold: true, prefix: true, channel: :error)
diff = Vagrant::Util::Experimental.features_valid?
if !diff.empty?
ui.error(I18n.t("vagrant.general.experimental.unknown_features", unknown: diff.join(", ")), bold: true, prefix: true, channel: :error)
end
end end
end end

View File

@ -1,9 +1,7 @@
module Vagrant module Vagrant
module Util module Util
class Experimental class Experimental
VALID_FEATURES = []
class << self class << self
# A method for determining if the experimental flag has been enabled with # A method for determining if the experimental flag has been enabled with
# any features # any features
# #
@ -27,7 +25,7 @@ module Vagrant
def global_enabled? def global_enabled?
if !defined?(@_global_enabled) if !defined?(@_global_enabled)
experimental = features_requested experimental = features_requested
if experimental.size == 1 && experimental.first == "1" || (experimental.size > 0 && experimental.sort == VALID_FEATURES.sort) if experimental.size == 1 && experimental.first == "1"
@_global_enabled = true @_global_enabled = true
else else
@_global_enabled = false @_global_enabled = false
@ -45,19 +43,7 @@ module Vagrant
experimental = features_requested experimental = features_requested
feature = feature.to_s feature = feature.to_s
return global_enabled? || (VALID_FEATURES.include?(feature) && experimental.include?(feature)) return global_enabled? || experimental.include?(feature)
end
# Determines if there are any unrecognized requested features
#
# @return [Array]
def features_valid?
if !defined?(@_features_diff)
@_features_diff = []
features = features_requested
features.each { |f| @_features_diff << f if !VALID_FEATURES.include?(f) }
end
@_features_diff
end end
# Returns the features requested for the experimental flag # Returns the features requested for the experimental flag

View File

@ -405,10 +405,6 @@ en:
Please use with caution, as some of the features may not be fully Please use with caution, as some of the features may not be fully
functional yet. functional yet.
unknown_features: |-
Requested unknown feature flags will be ignored:
Unknown: %{unknown}
not_in_installer: |- not_in_installer: |-
You appear to be running Vagrant outside of the official installers. You appear to be running Vagrant outside of the official installers.
Note that the installers are what ensure that Vagrant has all required Note that the installers are what ensure that Vagrant has all required

View File

@ -40,12 +40,6 @@ describe Vagrant::Util::Experimental do
expect(subject.global_enabled?).to eq(false) expect(subject.global_enabled?).to eq(false)
end end
it "returns true if enabled with a complete list of features" do
stub_const("Vagrant::Util::Experimental::VALID_FEATURES", ["list","of","features"])
allow(ENV).to receive(:[]).with("VAGRANT_EXPERIMENTAL").and_return("list,of,features")
expect(subject.global_enabled?).to eq(true)
end
it "returns false if disabled" do it "returns false if disabled" do
allow(ENV).to receive(:[]).with("VAGRANT_EXPERIMENTAL").and_return("0") allow(ENV).to receive(:[]).with("VAGRANT_EXPERIMENTAL").and_return("0")
expect(subject.global_enabled?).to eq(false) expect(subject.global_enabled?).to eq(false)
@ -58,10 +52,6 @@ describe Vagrant::Util::Experimental do
end end
describe "#feature_enabled?" do describe "#feature_enabled?" do
before(:each) do
stub_const("Vagrant::Util::Experimental::VALID_FEATURES", ["secret_feature"])
end
it "returns true if flag set to 1" do it "returns true if flag set to 1" do
allow(ENV).to receive(:[]).with("VAGRANT_EXPERIMENTAL").and_return("1") allow(ENV).to receive(:[]).with("VAGRANT_EXPERIMENTAL").and_return("1")
expect(subject.feature_enabled?("anything")).to eq(true) expect(subject.feature_enabled?("anything")).to eq(true)
@ -98,22 +88,6 @@ describe Vagrant::Util::Experimental do
end end
end end
describe "#features_valid" do
before(:each) do
stub_const("Vagrant::Util::Experimental::VALID_FEATURES", ["cool_feature", "other_feature", "secret_feature"])
end
it "returns an empty array if no diffs found" do
allow(ENV).to receive(:[]).with("VAGRANT_EXPERIMENTAL").and_return("cool_feature,other_feature")
expect(subject.features_valid?).to eq([])
end
it "returns the invalid flag if found" do
allow(ENV).to receive(:[]).with("VAGRANT_EXPERIMENTAL").and_return("fake_feature")
expect(subject.features_valid?).to eq(["fake_feature"])
end
end
describe "#features_requested" do describe "#features_requested" do
it "returns an array of requested features" do it "returns an array of requested features" do
allow(ENV).to receive(:[]).with("VAGRANT_EXPERIMENTAL").and_return("secret_feature,other_secret") allow(ENV).to receive(:[]).with("VAGRANT_EXPERIMENTAL").and_return("secret_feature,other_secret")
@ -122,10 +96,6 @@ describe Vagrant::Util::Experimental do
end end
describe "#guard_with" do describe "#guard_with" do
before(:each) do
stub_const("Vagrant::Util::Experimental::VALID_FEATURES", ["secret_feature"])
end
it "does not execute the block if the feature is not requested" do it "does not execute the block if the feature is not requested" do
allow(ENV).to receive(:[]).with("VAGRANT_EXPERIMENTAL").and_return(nil) allow(ENV).to receive(:[]).with("VAGRANT_EXPERIMENTAL").and_return(nil)
expect{|b| subject.guard_with("secret_feature", &b) }.not_to yield_control expect{|b| subject.guard_with("secret_feature", &b) }.not_to yield_control