-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove 1 level of recursion from the context metadata
- Loading branch information
Showing
3 changed files
with
59 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package gwlog | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestGetTrace(t *testing.T) { | ||
if GetTrace(context.TODO()) != "" { | ||
t.Errorf("expected context with no trace_id to return empty string") | ||
} | ||
|
||
if GetTrace(NewTrace(context.TODO())) == "" { | ||
t.Errorf("expected context with trace_id to return non-empty string") | ||
} | ||
} | ||
|
||
func TestMetadata(t *testing.T) { | ||
ctx := NewTrace(context.TODO()) | ||
AddMetadata(ctx, "foo", "bar") | ||
|
||
md := GetMetadata(ctx) | ||
mdMap := map[string]bool{} | ||
for _, m := range md { | ||
mdMap[fmt.Sprint(m)] = true | ||
} | ||
|
||
if !mdMap["foo"] || !mdMap["bar"] { | ||
t.Errorf("expected context to have metadata with key foo and val bar, got %s", md) | ||
} | ||
} |