...

Source file src/github.com/letsencrypt/boulder/features/features_test.go

Documentation: github.com/letsencrypt/boulder/features

     1  package features
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/letsencrypt/boulder/test"
     7  )
     8  
     9  func TestAllowUnrecognizedFeatures(t *testing.T) {
    10  	features = map[FeatureFlag]bool{
    11  		unused:                    false,
    12  		AllowUnrecognizedFeatures: false,
    13  	}
    14  	nameToFeature = map[string]FeatureFlag{
    15  		"unused":                    unused,
    16  		"AllowUnrecognizedFeatures": AllowUnrecognizedFeatures,
    17  	}
    18  	err := Set(map[string]bool{
    19  		"Z4lG0":                     true,
    20  		"AllowUnrecognizedFeatures": true,
    21  	})
    22  	test.AssertNotError(t, err, "expected no error when setting an unrecognized feature")
    23  
    24  	err = Set(map[string]bool{
    25  		"Z4lG0":                     true,
    26  		"Zombo":                     true,
    27  		"AllowUnrecognizedFeatures": false,
    28  	})
    29  	test.AssertError(t, err, "expected error when disallowing unrecognized features")
    30  	test.AssertContains(t, err.Error(), "unrecognized feature flag names: ")
    31  	test.AssertContains(t, err.Error(), "Z4lG0")
    32  	test.AssertContains(t, err.Error(), "Zombo")
    33  }
    34  
    35  func TestFeatures(t *testing.T) {
    36  	features = map[FeatureFlag]bool{
    37  		unused: false,
    38  	}
    39  	test.Assert(t, !Enabled(unused), "'unused' shouldn't be enabled")
    40  
    41  	err := Set(map[string]bool{"unused": true})
    42  	test.AssertNotError(t, err, "Set shouldn't have failed setting existing features")
    43  	test.Assert(t, Enabled(unused), "'unused' should be enabled")
    44  
    45  	Reset()
    46  	test.Assert(t, !Enabled(unused), "'unused' shouldn't be enabled")
    47  
    48  	err = Set(map[string]bool{"non-existent": true})
    49  	test.AssertError(t, err, "Set should've failed trying to enable a non-existent feature")
    50  
    51  	defer func() {
    52  		if r := recover(); r == nil {
    53  			t.Errorf("Enabled did not panic on an unknown feature")
    54  		}
    55  	}()
    56  	features = map[FeatureFlag]bool{}
    57  	Enabled(unused)
    58  }
    59  

View as plain text