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

View File

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