Capitalize feature gates

Also rename variables for clarity
pull/6/head
Tim Hockin 2016-08-22 12:05:14 -07:00
parent 6c75bd8be5
commit f77576bc2b
2 changed files with 50 additions and 50 deletions

View File

@ -33,24 +33,24 @@ const (
// To add a new feature, define a key for it below and add
// a featureSpec entry to knownFeatures.
// allAlpha is a global toggle for alpha features. Per-feature key
// values override the default set by allAlpha, if they come later in the
// allAlphaGate is a global toggle for alpha features. Per-feature key
// values override the default set by allAlphaGate, if they come later in the
// specification of gates. Examples:
// allAlpha=false,newFeature=true will result in newFeature=true
// allAlpha=true,newFeature=false will result in newFeature=false
allAlpha = "allAlpha"
// AllAlpha=false,NewFeature=true will result in newFeature=true
// AllAlpha=true,NewFeature=false will result in newFeature=false
allAlphaGate = "AllAlpha"
)
var (
// Default values for recorded features. Every new feature gate should be
// represented here.
knownFeatures = map[string]featureSpec{
allAlpha: {false, alpha},
allAlphaGate: {false, alpha},
}
// Special handling for a few gates.
specialFeatures = map[string]func(f *featureGate, val bool){
allAlpha: setUnsetAlphaGates,
allAlphaGate: setUnsetAlphaGates,
}
// DefaultFeatureGate is a shared global FeatureGate.

View File

@ -26,8 +26,8 @@ import (
func TestFeatureGateFlag(t *testing.T) {
// gates for testing
const testAlpha = "testAlpha"
const testBeta = "testBeta"
const testAlphaGate = "TestAlpha"
const testBetaGate = "TestBeta"
tests := []struct {
arg string
@ -37,91 +37,91 @@ func TestFeatureGateFlag(t *testing.T) {
{
arg: "",
expect: map[string]bool{
allAlpha: false,
testAlpha: false,
testBeta: false,
allAlphaGate: false,
testAlphaGate: false,
testBetaGate: false,
},
},
{
arg: "fooBarBaz=maybeidk",
expect: map[string]bool{
allAlpha: false,
testAlpha: false,
testBeta: false,
allAlphaGate: false,
testAlphaGate: false,
testBetaGate: false,
},
parseError: "unrecognized key: fooBarBaz",
},
{
arg: "allAlpha=false",
arg: "AllAlpha=false",
expect: map[string]bool{
allAlpha: false,
testAlpha: false,
testBeta: false,
allAlphaGate: false,
testAlphaGate: false,
testBetaGate: false,
},
},
{
arg: "allAlpha=true",
arg: "AllAlpha=true",
expect: map[string]bool{
allAlpha: true,
testAlpha: true,
testBeta: false,
allAlphaGate: true,
testAlphaGate: true,
testBetaGate: false,
},
},
{
arg: "allAlpha=banana",
arg: "AllAlpha=banana",
expect: map[string]bool{
allAlpha: false,
testAlpha: false,
testBeta: false,
allAlphaGate: false,
testAlphaGate: false,
testBetaGate: false,
},
parseError: "invalid value of allAlpha",
parseError: "invalid value of AllAlpha",
},
{
arg: "allAlpha=false,testAlpha=true",
arg: "AllAlpha=false,TestAlpha=true",
expect: map[string]bool{
allAlpha: false,
testAlpha: true,
testBeta: false,
allAlphaGate: false,
testAlphaGate: true,
testBetaGate: false,
},
},
{
arg: "testAlpha=true,allAlpha=false",
arg: "TestAlpha=true,AllAlpha=false",
expect: map[string]bool{
allAlpha: false,
testAlpha: true,
testBeta: false,
allAlphaGate: false,
testAlphaGate: true,
testBetaGate: false,
},
},
{
arg: "allAlpha=true,testAlpha=false",
arg: "AllAlpha=true,TestAlpha=false",
expect: map[string]bool{
allAlpha: true,
testAlpha: false,
testBeta: false,
allAlphaGate: true,
testAlphaGate: false,
testBetaGate: false,
},
},
{
arg: "testAlpha=false,allAlpha=true",
arg: "TestAlpha=false,AllAlpha=true",
expect: map[string]bool{
allAlpha: true,
testAlpha: false,
testBeta: false,
allAlphaGate: true,
testAlphaGate: false,
testBetaGate: false,
},
},
{
arg: "testBeta=true,allAlpha=false",
arg: "TestBeta=true,AllAlpha=false",
expect: map[string]bool{
allAlpha: false,
testAlpha: false,
testBeta: true,
allAlphaGate: false,
testAlphaGate: false,
testBetaGate: true,
},
},
}
for i, test := range tests {
fs := pflag.NewFlagSet("testfeaturegateflag", pflag.ContinueOnError)
f := DefaultFeatureGate
f.known[testAlpha] = featureSpec{false, alpha}
f.known[testBeta] = featureSpec{false, beta}
f.known[testAlphaGate] = featureSpec{false, alpha}
f.known[testBetaGate] = featureSpec{false, beta}
f.AddFlag(fs)
err := fs.Parse([]string{fmt.Sprintf("--%s=%s", flagName, test.arg)})