Skip to content

Commit

Permalink
test comments & var naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Catalin-Stratulat-Ericsson committed May 29, 2024
1 parent 7721087 commit 9242885
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/apiserver/webhooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,27 @@ 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
f()

// 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
}
Expand Down

0 comments on commit 9242885

Please sign in to comment.