-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow existing logger from context
We should reuse an existing context logger if in test context. This will allow test to setup act with a null logger to assert log messages. Co-authored-by: Markus Wolf <markus.wolf@new-work.se>
- Loading branch information
1 parent
f726339
commit be91b48
Showing
2 changed files
with
26 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package common | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type testFlagContextKey string | ||
|
||
const testFlagContextKeyVal = testFlagContextKey("test-context") | ||
|
||
// TestContext returns whether the context has the test flag set | ||
func TestContext(ctx context.Context) bool { | ||
val := ctx.Value(testFlagContextKeyVal) | ||
return val != nil | ||
} | ||
|
||
// WithTextContext sets the test flag in the context | ||
func WithTestContext(ctx context.Context) context.Context { | ||
return context.WithValue(ctx, testFlagContextKeyVal, true) | ||
} |
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