aboutsummaryrefslogtreecommitdiffstats
path: root/integrations/testlogger.go
diff options
context:
space:
mode:
Diffstat (limited to 'integrations/testlogger.go')
-rw-r--r--integrations/testlogger.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/integrations/testlogger.go b/integrations/testlogger.go
index 43a1471f66..91b94ac9f3 100644
--- a/integrations/testlogger.go
+++ b/integrations/testlogger.go
@@ -10,6 +10,7 @@ import (
"os"
"runtime"
"strings"
+ "sync"
"testing"
"code.gitea.io/gitea/modules/log"
@@ -25,11 +26,21 @@ type TestLogger struct {
var writerCloser = &testLoggerWriterCloser{}
type testLoggerWriterCloser struct {
+ sync.RWMutex
t testing.TB
}
+func (w *testLoggerWriterCloser) setT(t *testing.TB) {
+ w.Lock()
+ w.t = *t
+ w.Unlock()
+}
+
func (w *testLoggerWriterCloser) Write(p []byte) (int, error) {
- if w.t != nil {
+ w.RLock()
+ t := w.t
+ w.RUnlock()
+ if t != nil {
if len(p) > 0 && p[len(p)-1] == '\n' {
p = p[:len(p)-1]
}
@@ -54,7 +65,7 @@ func (w *testLoggerWriterCloser) Write(p []byte) (int, error) {
}
}()
- w.t.Log(string(p))
+ t.Log(string(p))
return len(p), nil
}
return len(p), nil
@@ -77,7 +88,7 @@ func PrintCurrentTest(t testing.TB, skip ...int) {
} else {
fmt.Fprintf(os.Stdout, "=== %s (%s:%d)\n", t.Name(), strings.TrimPrefix(filename, prefix), line)
}
- writerCloser.t = t
+ writerCloser.setT(&t)
}
// Printf takes a format and args and prints the string to os.Stdout