Skip to content

Commit

Permalink
Merge pull request kubernetes#193 from yuzhiquan/newflag-check
Browse files Browse the repository at this point in the history
Check new klog flag's prefix
  • Loading branch information
k8s-ci-robot authored Nov 11, 2020
2 parents d47f4e8 + 5919b2f commit 199a06d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions klog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1395,3 +1395,36 @@ func (l *testLogr) WithName(string) logr.Logger { panic("not implemented") }
func (l *testLogr) WithValues(...interface{}) logr.Logger {
panic("not implemented")
}

// existedFlag contains all existed flag, without KlogPrefix
var existedFlag = map[string]struct{}{
"log_dir": {},
"add_dir_header": {},
"alsologtostderr": {},
"log_backtrace_at": {},
"log_file": {},
"log_file_max_size": {},
"logtostderr": {},
"one_output": {},
"skip_headers": {},
"skip_log_headers": {},
"stderrthreshold": {},
"v": {},
"vmodule": {},
}

// KlogPrefix define new flag prefix
const KlogPrefix string = "klog"

// TestKlogFlagPrefix check every klog flag's prefix, exclude flag in existedFlag
func TestKlogFlagPrefix(t *testing.T) {
fs := &flag.FlagSet{}
InitFlags(fs)
fs.VisitAll(func(f *flag.Flag) {
if _, found := existedFlag[f.Name]; !found {
if !strings.HasPrefix(f.Name, KlogPrefix) {
t.Errorf("flag %s not have klog prefix: %s", f.Name, KlogPrefix)
}
}
})
}

0 comments on commit 199a06d

Please sign in to comment.