Skip to content

Commit

Permalink
Merge pull request #3330 from maqiuyujoyce/202412-enable-klog
Browse files Browse the repository at this point in the history
Enable klog in dynamic test
  • Loading branch information
google-oss-prow[bot] authored Dec 13, 2024
2 parents 55164ad + de3779c commit c3a37f7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/GoogleCloudPlatform/k8s-config-connector

go 1.22
go 1.22.0

toolchain go1.23.2

Expand Down Expand Up @@ -224,12 +224,12 @@ require (
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/term v0.26.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/tools v0.24.0 // indirect
golang.org/x/tools v0.27.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions pkg/test/main/testmain.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package testmain

import (
"flag"
"io"
"log"
"os"
Expand All @@ -29,6 +30,7 @@ import (
cnrmwebhook "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/webhook"

apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/manager"
)
Expand All @@ -42,7 +44,26 @@ func ForIntegrationTests(m *testing.M, mgr *manager.Manager) {
// here we discard everything logged onto the Go standard logger to
// disable logging from Terraform Google provider in integration tests.
log.SetOutput(io.Discard)
if err := flag.Set("alsologtostderr", "true"); err != nil {
log.Fatalf("error setting alsologtostderr to true: %v", err)
}
flag.Parse()

klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
klog.InitFlags(klogFlags)

// Sync the log and klog flags.
flag.CommandLine.VisitAll(func(f1 *flag.Flag) {
f2 := klogFlags.Lookup(f1.Name)
if f2 != nil {
value := f1.Value.String()
if err := f2.Value.Set(value); err != nil {
log.Fatalf("error setting %v to %v: %v", f2, value, err)
}
}
})
TestMain(m, test.IntegrationTestType, nil, mgr)
klog.Flush()
}

func ForUnitTests(m *testing.M, mgr *manager.Manager) {
Expand Down

0 comments on commit c3a37f7

Please sign in to comment.