From 34bd1e391e5815110589d4157442ad0a5a39169f Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Mon, 22 Aug 2016 17:37:07 -0700 Subject: [PATCH] Don't panic if the feature-gate flag was not used --- pkg/util/config/feature_gate.go | 9 ++++----- pkg/util/config/feature_gate_test.go | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/pkg/util/config/feature_gate.go b/pkg/util/config/feature_gate.go index 004a17ffa1..f8777d58c9 100644 --- a/pkg/util/config/feature_gate.go +++ b/pkg/util/config/feature_gate.go @@ -156,11 +156,10 @@ func (f *featureGate) Type() string { func (f *featureGate) lookup(key string) bool { defaultValue := f.known[key].enabled - if f.enabled == nil { - panic(fmt.Sprintf("--%s has not been parsed", flagName)) - } - if v, ok := f.enabled[key]; ok { - return v + if f.enabled != nil { + if v, ok := f.enabled[key]; ok { + return v + } } return defaultValue diff --git a/pkg/util/config/feature_gate_test.go b/pkg/util/config/feature_gate_test.go index addf59ad5e..02b90b88f8 100644 --- a/pkg/util/config/feature_gate_test.go +++ b/pkg/util/config/feature_gate_test.go @@ -139,3 +139,21 @@ func TestFeatureGateFlag(t *testing.T) { } } } + +func TestFeatureGateFlagDefaults(t *testing.T) { + // gates for testing + const testAlphaGate = "TestAlpha" + const testBetaGate = "TestBeta" + + // Don't parse the flag, assert defaults are used. + f := DefaultFeatureGate + f.known[testAlphaGate] = featureSpec{false, alpha} + f.known[testBetaGate] = featureSpec{true, beta} + + if f.lookup(testAlphaGate) != false { + t.Errorf("Expected false") + } + if f.lookup(testBetaGate) != true { + t.Errorf("Expected true") + } +}