diff --git a/examples/output_test/output_test.go b/examples/output_test/output_test.go index bd4e4787..697dc459 100644 --- a/examples/output_test/output_test.go +++ b/examples/output_test/output_test.go @@ -34,33 +34,6 @@ import ( "k8s.io/klog/v2/textlogger" ) -// TestKlogOutput tests klog output without a logger. -func TestKlogOutput(t *testing.T) { - test.InitKlog(t) - test.Output(t, test.OutputConfig{}) -} - -// TestTextloggerOutput tests the textlogger, directly and as backend. -func TestTextloggerOutput(t *testing.T) { - test.InitKlog(t) - newLogger := func(out io.Writer, v int, vmodule string) logr.Logger { - config := textlogger.NewConfig( - textlogger.Verbosity(v), - textlogger.Output(out), - ) - if err := config.VModule().Set(vmodule); err != nil { - panic(err) - } - return textlogger.NewLogger(config) - } - t.Run("direct", func(t *testing.T) { - test.Output(t, test.OutputConfig{NewLogger: newLogger, SupportsVModule: true}) - }) - t.Run("klog-backend", func(t *testing.T) { - test.Output(t, test.OutputConfig{NewLogger: newLogger, AsBackend: true}) - }) -} - // TestZaprOutput tests the zapr, directly and as backend. func TestZaprOutput(t *testing.T) { test.InitKlog(t) @@ -75,16 +48,6 @@ func TestZaprOutput(t *testing.T) { }) } -// TestKlogrOutput tests klogr output via klog. -func TestKlogrOutput(t *testing.T) { - test.InitKlog(t) - test.Output(t, test.OutputConfig{ - NewLogger: func(out io.Writer, v int, vmodule string) logr.Logger { - return klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog)) - }, - }) -} - // TestKlogrStackText tests klogr.klogr -> klog -> text logger. func TestKlogrStackText(t *testing.T) { test.InitKlog(t) diff --git a/klogr/output_test.go b/klogr/output_test.go new file mode 100644 index 00000000..aa87e953 --- /dev/null +++ b/klogr/output_test.go @@ -0,0 +1,37 @@ +/* +Copyright 2022 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 klogr_test + +import ( + "io" + "testing" + + "github.com/go-logr/logr" + + "k8s.io/klog/v2/klogr" + "k8s.io/klog/v2/test" +) + +// TestKlogrOutput tests klogr output via klog. +func TestKlogrOutput(t *testing.T) { + test.InitKlog(t) + test.Output(t, test.OutputConfig{ + NewLogger: func(out io.Writer, v int, vmodule string) logr.Logger { + return klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog)) + }, + }) +} diff --git a/output_test.go b/output_test.go new file mode 100644 index 00000000..7e38e12c --- /dev/null +++ b/output_test.go @@ -0,0 +1,43 @@ +/* +Copyright 2022 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 klog_test + +import ( + "io" + "testing" + + "github.com/go-logr/logr" + + "k8s.io/klog/v2" + "k8s.io/klog/v2/test" +) + +// TestKlogOutput tests klog output without a logger. +func TestKlogOutput(t *testing.T) { + test.InitKlog(t) + test.Output(t, test.OutputConfig{}) +} + +// TestKlogKlogrOutput tests klogr output via klog, using the klog/v2 klogr. +func TestKlogrOutput(t *testing.T) { + test.InitKlog(t) + test.Output(t, test.OutputConfig{ + NewLogger: func(out io.Writer, v int, vmodule string) logr.Logger { + return klog.NewKlogr() + }, + }) +} diff --git a/textlogger/output_test.go b/textlogger/output_test.go new file mode 100644 index 00000000..9a3bc95e --- /dev/null +++ b/textlogger/output_test.go @@ -0,0 +1,48 @@ +/* +Copyright 2022 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 textlogger_test + +import ( + "io" + "testing" + + "github.com/go-logr/logr" + + "k8s.io/klog/v2/test" + "k8s.io/klog/v2/textlogger" +) + +// TestTextloggerOutput tests the textlogger, directly and as backend. +func TestTextloggerOutput(t *testing.T) { + test.InitKlog(t) + newLogger := func(out io.Writer, v int, vmodule string) logr.Logger { + config := textlogger.NewConfig( + textlogger.Verbosity(v), + textlogger.Output(out), + ) + if err := config.VModule().Set(vmodule); err != nil { + panic(err) + } + return textlogger.NewLogger(config) + } + t.Run("direct", func(t *testing.T) { + test.Output(t, test.OutputConfig{NewLogger: newLogger, SupportsVModule: true}) + }) + t.Run("klog-backend", func(t *testing.T) { + test.Output(t, test.OutputConfig{NewLogger: newLogger, AsBackend: true}) + }) +}