mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Handle metrics.StabilityLevel default value better.
Provide a method setDefault() to StabilityLevel type. Update bazel by hack/update-bazel.sh
This commit is contained in:
parent
f243640e22
commit
9ec270804a
@ -41,6 +41,7 @@ go_test(
|
|||||||
"counter_test.go",
|
"counter_test.go",
|
||||||
"gauge_test.go",
|
"gauge_test.go",
|
||||||
"histogram_test.go",
|
"histogram_test.go",
|
||||||
|
"opts_test.go",
|
||||||
"registry_test.go",
|
"registry_test.go",
|
||||||
"summary_test.go",
|
"summary_test.go",
|
||||||
"version_parser_test.go",
|
"version_parser_test.go",
|
||||||
|
@ -53,6 +53,16 @@ const (
|
|||||||
STABLE StabilityLevel = "STABLE"
|
STABLE StabilityLevel = "STABLE"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// setDefaults takes 'ALPHA' in case of empty.
|
||||||
|
func (sl *StabilityLevel) setDefaults() {
|
||||||
|
switch *sl {
|
||||||
|
case "":
|
||||||
|
*sl = ALPHA
|
||||||
|
default:
|
||||||
|
// no-op, since we have a StabilityLevel already
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// CounterOpts is an alias for Opts. See there for doc comments.
|
// CounterOpts is an alias for Opts. See there for doc comments.
|
||||||
type CounterOpts KubeOpts
|
type CounterOpts KubeOpts
|
||||||
|
|
||||||
|
61
staging/src/k8s.io/component-base/metrics/opts_test.go
Normal file
61
staging/src/k8s.io/component-base/metrics/opts_test.go
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2019 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package metrics
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDefaultStabilityLevel(t *testing.T) {
|
||||||
|
var tests = []struct {
|
||||||
|
name string
|
||||||
|
inputValue StabilityLevel
|
||||||
|
expectValue StabilityLevel
|
||||||
|
expectPanic bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "empty should take ALPHA by default",
|
||||||
|
inputValue: "",
|
||||||
|
expectValue: ALPHA,
|
||||||
|
expectPanic: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ALPHA remain unchanged",
|
||||||
|
inputValue: ALPHA,
|
||||||
|
expectValue: ALPHA,
|
||||||
|
expectPanic: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "STABLE remain unchanged",
|
||||||
|
inputValue: STABLE,
|
||||||
|
expectValue: STABLE,
|
||||||
|
expectPanic: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range tests {
|
||||||
|
tc := tc
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
var stability = tc.inputValue
|
||||||
|
|
||||||
|
stability.setDefaults()
|
||||||
|
if stability != tc.expectValue {
|
||||||
|
t.Errorf("Got %s, expected: %v ", stability, tc.expectValue)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user