mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-04 01:09:36 +02:00
chore(deps): bump github.com/spf13/viper from 1.16.0 to 1.18.2 (#4861)
* chore(deps): bump github.com/spf13/viper from 1.16.0 to 1.18.2 Bumps [github.com/spf13/viper](https://github.com/spf13/viper) from 1.16.0 to 1.18.2. - [Release notes](https://github.com/spf13/viper/releases) - [Commits](https://github.com/spf13/viper/compare/v1.16.0...v1.18.2) --- updated-dependencies: - dependency-name: github.com/spf13/viper dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * fix race --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Caleb Doxsey <cdoxsey@pomerium.com>
This commit is contained in:
parent
07d608792f
commit
615c6257e6
7 changed files with 143 additions and 127 deletions
|
@ -1,23 +1,50 @@
|
|||
package testutil
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/pomerium/pomerium/internal/log"
|
||||
)
|
||||
|
||||
// SetLogger sets the given logger as the global logger for the remainder of
|
||||
// the current test. Because the logger is global, this must not be called from
|
||||
// parallel tests.
|
||||
func SetLogger(t *testing.T, logger zerolog.Logger) {
|
||||
// CaptureLogs captures any logs made during the test. Time will be stripped.
|
||||
// Any tests that use it should not be run in parallel.
|
||||
func CaptureLogs(t *testing.T, f func()) string {
|
||||
t.Helper()
|
||||
|
||||
originalLogger := log.Logger
|
||||
t.Cleanup(func() { log.Logger = originalLogger })
|
||||
log.Logger = logger
|
||||
pr, pw := io.Pipe()
|
||||
log.Writer.Add(pw)
|
||||
defer log.Writer.Remove(pw)
|
||||
|
||||
originalContextLogger := zerolog.DefaultContextLogger
|
||||
t.Cleanup(func() { zerolog.DefaultContextLogger = originalContextLogger })
|
||||
zerolog.DefaultContextLogger = &logger
|
||||
var buf bytes.Buffer
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
d := json.NewDecoder(pr)
|
||||
for {
|
||||
var m map[string]any
|
||||
if d.Decode(&m) != nil {
|
||||
break
|
||||
}
|
||||
delete(m, "time")
|
||||
bs, _ := json.Marshal(m)
|
||||
buf.Write(bs)
|
||||
buf.WriteByte('\n')
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
f()
|
||||
|
||||
pw.Close()
|
||||
}()
|
||||
wg.Wait()
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue