Skip to content

Commit

Permalink
Moce tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric committed Jul 18, 2024
1 parent 2e4854a commit 7a1dcf3
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 71 deletions.
76 changes: 76 additions & 0 deletions hub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"strings"
"sync"
"testing"

Expand Down Expand Up @@ -408,6 +409,81 @@ func TestHub_ContinueTrace(t *testing.T) {
}
}

func TestGetTraceparent(t *testing.T) {
tests := map[string]struct {
hub *Hub
expected string
}{
"With span": {
hub: func() *Hub {
h, _, s := setupHubTest()
s.span = &Span{
TraceID: TraceIDFromHex("d49d9bf66f13450b81f65bc51cf49c03"),
SpanID: SpanIDFromHex("a9f442f9330b4e09"),
Sampled: SampledTrue,
}
return h
}(),
expected: "d49d9bf66f13450b81f65bc51cf49c03-a9f442f9330b4e09-1",
},
"Without span": {
hub: func() *Hub {
h, _, s := setupHubTest()
s.propagationContext.TraceID = TraceIDFromHex("d49d9bf66f13450b81f65bc51cf49c03")
s.propagationContext.SpanID = SpanIDFromHex("a9f442f9330b4e09")
return h
}(),
expected: "d49d9bf66f13450b81f65bc51cf49c03-a9f442f9330b4e09",
},
}

for name, tt := range tests {
t.Run(name, func(t *testing.T) {
result := tt.hub.GetTraceparent()
assertEqual(t, tt.expected, result)
})
}
}

func TestGetBaggageHeader(t *testing.T) {
tests := map[string]struct {
hub *Hub
expected string
}{
"With span": {
hub: func() *Hub {
h, _, s := setupHubTest()
s.span = &Span{
dynamicSamplingContext: DynamicSamplingContext{
Entries: map[string]string{"sample_rate": "1", "release": "1.0.0", "environment": "production"},
},
}
return h
}(),
expected: "sentry-sample_rate=1,sentry-environment=production,sentry-release=1.0.0",
},
"Without span": {
hub: func() *Hub {
h, _, s := setupHubTest()
s.propagationContext.DynamicSamplingContext = DynamicSamplingContext{
Entries: map[string]string{"release": "1.0.0", "environment": "production"},
}
return h
}(),
expected: "sentry-environment=production,sentry-release=1.0.0",
},
}

for name, tt := range tests {
t.Run(name, func(t *testing.T) {
result := tt.hub.GetBaggage()
res := strings.Split(result, ",")
sortSlice(res)
assertEqual(t, tt.expected, strings.Join(res, ","))
})
}
}

func TestGetHubFromContext(t *testing.T) {
hub, _, _ := setupHubTest()
ctx := context.Background()
Expand Down
71 changes: 0 additions & 71 deletions tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,77 +482,6 @@ func TestToSentryTrace(t *testing.T) {
}
}

// func TestGetTraceHeader(t *testing.T) {
// tests := map[string]struct {
// scope *Scope
// expected string
// }{
// "With span": {
// scope: func() *Scope {
// s := NewScope()
// s.span = &Span{
// TraceID: TraceIDFromHex("d49d9bf66f13450b81f65bc51cf49c03"),
// SpanID: SpanIDFromHex("a9f442f9330b4e09"),
// Sampled: SampledTrue,
// }
// return s
// }(),
// expected: "d49d9bf66f13450b81f65bc51cf49c03-a9f442f9330b4e09-1",
// },
// "Without span": {
// scope: func() *Scope {
// s := NewScope()
// s.propagationContext.TraceID = TraceIDFromHex("d49d9bf66f13450b81f65bc51cf49c03")
// s.propagationContext.SpanID = SpanIDFromHex("a9f442f9330b4e09")
// return s
// }(),
// expected: "d49d9bf66f13450b81f65bc51cf49c03-a9f442f9330b4e09",
// },
// }

// for name, tt := range tests {
// t.Run(name, func(t *testing.T) {
// result := GetTraceHeader(tt.scope)
// assertEqual(t, tt.expected, result)
// })
// }
// }

// func TestGetBaggageHeader(t *testing.T) {
// tests := map[string]struct {
// scope *Scope
// expected string
// }{
// "With span": {
// scope: func() *Scope {
// s := NewScope()
// s.span = &Span{}
// return s
// }(),
// expected: "",
// },
// "Without span": {
// scope: func() *Scope {
// s := NewScope()
// s.propagationContext.DynamicSamplingContext = DynamicSamplingContext{
// Entries: map[string]string{"release": "1.0.0", "environment": "production"},
// }
// return s
// }(),
// expected: "sentry-environment=production,sentry-release=1.0.0",
// },
// }

// for name, tt := range tests {
// t.Run(name, func(t *testing.T) {
// result := GetBaggageHeader(tt.scope)
// res := strings.Split(result, ",")
// sortSlice(res)
// assertEqual(t, tt.expected, strings.Join(res, ","))
// })
// }
// }

func TestContinueSpanFromRequest(t *testing.T) {
traceID := TraceIDFromHex("bc6d53f15eb88f4320054569b8c553d4")
spanID := SpanIDFromHex("b72fa28504b07285")
Expand Down

0 comments on commit 7a1dcf3

Please sign in to comment.