forked from golang/glog
-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previously it was necessary to enter the "examples" module to run output tests for code in the main module. Now "go test ./..." at the root or in individual directories also runs these tests.
- Loading branch information
Showing
4 changed files
with
128 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}) | ||
}) | ||
} |