Use the new log capturing helper in all tests

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
Yusuke Kuoka
2022-11-13 08:53:53 +00:00
parent 235917c11c
commit 8d2aec249d
11 changed files with 38 additions and 391 deletions
+3 -30
View File
@@ -1,9 +1,6 @@
package app
import (
"bufio"
"bytes"
"io"
"sync"
"testing"
@@ -1324,32 +1321,8 @@ changing working directory back to "/path/to"
ReleasesMutex: &sync.Mutex{},
}
bs := &bytes.Buffer{}
func() {
logReader, logWriter := io.Pipe()
logFlushed := &sync.WaitGroup{}
// Ensure all the log is consumed into `bs` by calling `logWriter.Close()` followed by `logFlushed.Wait()`
logFlushed.Add(1)
go func() {
scanner := bufio.NewScanner(logReader)
for scanner.Scan() {
bs.Write(scanner.Bytes())
bs.WriteString("\n")
}
logFlushed.Done()
}()
defer func() {
// This is here to avoid data-trace on bytes buffer `bs` to capture logs
if err := logWriter.Close(); err != nil {
panic(err)
}
logFlushed.Wait()
}()
logger := helmexec.NewLogger(logWriter, "debug")
bs := runWithLogCapture(t, "debug", func(t *testing.T, logger *zap.SugaredLogger) {
t.Helper()
valsRuntime, err := vals.New(vals.Options{CacheSize: 32})
if err != nil {
@@ -1429,7 +1402,7 @@ changing working directory back to "/path/to"
}
}
}
}()
})
if tc.log != "" {
actual := bs.String()