This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from DataDog/jlegrone/test-logger
Route temporaltest logs to testing.T logger
- Loading branch information
Showing
8 changed files
with
269 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package temporaltest | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
type testLogger struct { | ||
t *testing.T | ||
} | ||
|
||
func (tl *testLogger) logLevel(lvl, msg string, keyvals ...interface{}) { | ||
if tl.t == nil { | ||
return | ||
} | ||
args := []interface{}{lvl, msg} | ||
args = append(args, keyvals...) | ||
tl.t.Log(args...) | ||
} | ||
|
||
func (tl *testLogger) Debug(msg string, keyvals ...interface{}) { | ||
tl.logLevel("DEBUG", msg, keyvals) | ||
} | ||
|
||
func (tl *testLogger) Info(msg string, keyvals ...interface{}) { | ||
tl.logLevel("INFO ", msg, keyvals) | ||
} | ||
|
||
func (tl *testLogger) Warn(msg string, keyvals ...interface{}) { | ||
tl.logLevel("WARN ", msg, keyvals) | ||
} | ||
|
||
func (tl *testLogger) Error(msg string, keyvals ...interface{}) { | ||
tl.logLevel("ERROR", msg, keyvals) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License. | ||
// | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc. | ||
|
||
package temporaltest | ||
|
||
import "testing" | ||
|
||
type TestServerOption interface { | ||
apply(*TestServer) | ||
} | ||
|
||
// WithT directs all worker and client logs to the test logger. | ||
func WithT(t *testing.T) TestServerOption { | ||
return newApplyFuncContainer(func(server *TestServer) { | ||
server.t = t | ||
}) | ||
} | ||
|
||
type applyFuncContainer struct { | ||
applyInternal func(*TestServer) | ||
} | ||
|
||
func (fso *applyFuncContainer) apply(ts *TestServer) { | ||
fso.applyInternal(ts) | ||
} | ||
|
||
func newApplyFuncContainer(apply func(*TestServer)) *applyFuncContainer { | ||
return &applyFuncContainer{ | ||
applyInternal: apply, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters