27 lines
611 B
Go
27 lines
611 B
Go
package apiresponse
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestTraceIDContext(t *testing.T) {
|
|
ctx := WithTraceID(context.Background(), "abc")
|
|
if got := TraceIDFromContext(ctx); got != "abc" {
|
|
t.Fatalf("TraceIDFromContext() = %q, want abc", got)
|
|
}
|
|
if got := TraceIDFromContext(context.Background()); got != "" {
|
|
t.Fatalf("TraceIDFromContext(empty) = %q, want empty", got)
|
|
}
|
|
}
|
|
|
|
func TestGenerateTraceID(t *testing.T) {
|
|
id := GenerateTraceID()
|
|
if id == "" {
|
|
t.Fatal("GenerateTraceID returned empty string")
|
|
}
|
|
if id == GenerateTraceID() {
|
|
t.Fatal("GenerateTraceID returned duplicate values")
|
|
}
|
|
}
|