mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-16 22:53:22 +00:00
add unit test coverage
Change-Id: Idfbc9e72f1e0051a9423b23d1f0397364bb3c251
This commit is contained in:
@@ -429,22 +429,29 @@ func TestFeatureGateMetrics(t *testing.T) {
|
|||||||
featuremetrics.ResetFeatureInfoMetric()
|
featuremetrics.ResetFeatureInfoMetric()
|
||||||
const testAlphaGate Feature = "TestAlpha"
|
const testAlphaGate Feature = "TestAlpha"
|
||||||
const testBetaGate Feature = "TestBeta"
|
const testBetaGate Feature = "TestBeta"
|
||||||
|
const testAlphaEnabled Feature = "TestAlphaEnabled"
|
||||||
|
const testBetaDisabled Feature = "TestBetaDisabled"
|
||||||
testedMetrics := []string{"kubernetes_feature_enabled"}
|
testedMetrics := []string{"kubernetes_feature_enabled"}
|
||||||
expectedOutput := `
|
expectedOutput := `
|
||||||
# HELP kubernetes_feature_enabled [ALPHA] This metric records the data about the stage and enablement of a k8s feature.
|
# HELP kubernetes_feature_enabled [ALPHA] This metric records the data about the stage and enablement of a k8s feature.
|
||||||
# TYPE kubernetes_feature_enabled gauge
|
# TYPE kubernetes_feature_enabled gauge
|
||||||
kubernetes_feature_enabled{name="TestAlpha",stage="ALPHA"} 0
|
kubernetes_feature_enabled{name="TestAlpha",stage="ALPHA"} 0
|
||||||
kubernetes_feature_enabled{name="TestBeta",stage="BETA"} 1
|
kubernetes_feature_enabled{name="TestBeta",stage="BETA"} 1
|
||||||
|
kubernetes_feature_enabled{name="TestAlphaEnabled",stage="ALPHA"} 1
|
||||||
kubernetes_feature_enabled{name="AllAlpha",stage="ALPHA"} 0
|
kubernetes_feature_enabled{name="AllAlpha",stage="ALPHA"} 0
|
||||||
kubernetes_feature_enabled{name="AllBeta",stage="BETA"} 0
|
kubernetes_feature_enabled{name="AllBeta",stage="BETA"} 0
|
||||||
|
kubernetes_feature_enabled{name="TestBetaDisabled",stage="ALPHA"} 0
|
||||||
`
|
`
|
||||||
|
|
||||||
f := NewFeatureGate()
|
f := NewFeatureGate()
|
||||||
fMap := map[Feature]FeatureSpec{
|
fMap := map[Feature]FeatureSpec{
|
||||||
testAlphaGate: {Default: false, PreRelease: Alpha},
|
testAlphaGate: {Default: false, PreRelease: Alpha},
|
||||||
testBetaGate: {Default: true, PreRelease: Beta},
|
testAlphaEnabled: {Default: false, PreRelease: Alpha},
|
||||||
|
testBetaGate: {Default: true, PreRelease: Beta},
|
||||||
|
testBetaDisabled: {Default: true, PreRelease: Alpha},
|
||||||
}
|
}
|
||||||
f.Add(fMap)
|
f.Add(fMap)
|
||||||
|
f.SetFromMap(map[string]bool{"TestAlphaEnabled": true, "TestBetaDisabled": false})
|
||||||
f.AddMetrics()
|
f.AddMetrics()
|
||||||
if err := testutil.GatherAndCompare(legacyregistry.DefaultGatherer, strings.NewReader(expectedOutput), testedMetrics...); err != nil {
|
if err := testutil.GatherAndCompare(legacyregistry.DefaultGatherer, strings.NewReader(expectedOutput), testedMetrics...); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
Reference in New Issue
Block a user