diff --git a/pkg/apiserver/webhooks_test.go b/pkg/apiserver/webhooks_test.go index 512a2835..e20ebe1d 100644 --- a/pkg/apiserver/webhooks_test.go +++ b/pkg/apiserver/webhooks_test.go @@ -97,18 +97,18 @@ func TestLoadCertificate(t *testing.T) { require.Error(t, err3) certModTime = time.Time{} } - +// method for capturing klog error's func captureStderr(f func()) string { - r, w, _ := os.Pipe() + read, write, _ := os.Pipe() stderr := os.Stderr - os.Stderr = w - outC := make(chan string) + os.Stderr = write + outputChannel := make(chan string) // Copy the output in a separate goroutine so printing can't block indefinitely. go func() { var buf bytes.Buffer - io.Copy(&buf, r) - outC <- buf.String() + io.Copy(&buf, read) + outputChannel <- buf.String() }() // Run the provided function and capture the stderr output @@ -116,8 +116,8 @@ func captureStderr(f func()) string { // Restore the original stderr and close the write-end of the pipe so the goroutine will exit os.Stderr = stderr - w.Close() - out := <-outC + write.Close() + out := <-outputChannel return out }