Add pkg/logs/testing package

Signed-off-by: James Munnelly <james@munnelly.eu>
This commit is contained in:
James Munnelly 2020-03-25 09:06:00 +00:00
parent b0fe0a8e4d
commit f5050b7828
3 changed files with 81 additions and 1 deletions

View File

@ -26,7 +26,10 @@ filegroup(
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
srcs = [
":package-srcs",
"//pkg/logs/testing:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@ -0,0 +1,23 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = ["log_testing.go"],
importpath = "github.com/jetstack/cert-manager/pkg/logs/testing",
visibility = ["//visibility:public"],
deps = ["@com_github_go_logr_logr//:go_default_library"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@ -0,0 +1,54 @@
/*
Copyright 2020 The Jetstack cert-manager contributors.
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 testing
import (
"testing"
"github.com/go-logr/logr"
)
// TestLogger is a logr.Logger that prints through a testing.T object.
type TestLogger struct {
T *testing.T
}
var _ logr.Logger = TestLogger{}
func (_ TestLogger) Enabled() bool {
return true
}
func (log TestLogger) Info(msg string, args ...interface{}) {
log.T.Logf("%s: %v", msg, args)
}
func (log TestLogger) Error(err error, msg string, args ...interface{}) {
log.T.Logf("%s: %v -- %v", msg, err, args)
}
func (log TestLogger) V(v int) logr.InfoLogger {
return log
}
func (log TestLogger) WithName(_ string) logr.Logger {
return log
}
func (log TestLogger) WithValues(_ ...interface{}) logr.Logger {
return log
}