Skip to content

Commit de3779c

Browse files
committed
Enable klog in dynamic test
1 parent 2f35b56 commit de3779c

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/GoogleCloudPlatform/k8s-config-connector
22

3-
go 1.22
3+
go 1.22.0
44

55
toolchain go1.23.2
66

@@ -224,12 +224,12 @@ require (
224224
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
225225
go.uber.org/multierr v1.10.0 // indirect
226226
golang.org/x/crypto v0.29.0 // indirect
227-
golang.org/x/mod v0.20.0 // indirect
227+
golang.org/x/mod v0.22.0 // indirect
228228
golang.org/x/net v0.31.0 // indirect
229229
golang.org/x/sys v0.27.0 // indirect
230230
golang.org/x/term v0.26.0 // indirect
231231
golang.org/x/text v0.20.0 // indirect
232-
golang.org/x/tools v0.24.0 // indirect
232+
golang.org/x/tools v0.27.0 // indirect
233233
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
234234
google.golang.org/appengine v1.6.8 // indirect
235235
gopkg.in/inf.v0 v0.9.1 // indirect

go.sum

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/test/main/testmain.go

+21
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package testmain
1616

1717
import (
18+
"flag"
1819
"io"
1920
"log"
2021
"os"
@@ -29,6 +30,7 @@ import (
2930
cnrmwebhook "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/webhook"
3031

3132
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
33+
"k8s.io/klog/v2"
3234
"sigs.k8s.io/controller-runtime/pkg/envtest"
3335
"sigs.k8s.io/controller-runtime/pkg/manager"
3436
)
@@ -42,7 +44,26 @@ func ForIntegrationTests(m *testing.M, mgr *manager.Manager) {
4244
// here we discard everything logged onto the Go standard logger to
4345
// disable logging from Terraform Google provider in integration tests.
4446
log.SetOutput(io.Discard)
47+
if err := flag.Set("alsologtostderr", "true"); err != nil {
48+
log.Fatalf("error setting alsologtostderr to true: %v", err)
49+
}
50+
flag.Parse()
51+
52+
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
53+
klog.InitFlags(klogFlags)
54+
55+
// Sync the log and klog flags.
56+
flag.CommandLine.VisitAll(func(f1 *flag.Flag) {
57+
f2 := klogFlags.Lookup(f1.Name)
58+
if f2 != nil {
59+
value := f1.Value.String()
60+
if err := f2.Value.Set(value); err != nil {
61+
log.Fatalf("error setting %v to %v: %v", f2, value, err)
62+
}
63+
}
64+
})
4565
TestMain(m, test.IntegrationTestType, nil, mgr)
66+
klog.Flush()
4667
}
4768

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

0 commit comments

Comments
 (0)