-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorrelation_id_test.go
More file actions
80 lines (62 loc) · 1.77 KB
/
correlation_id_test.go
File metadata and controls
80 lines (62 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package xtransport_test
import (
"context"
"regexp"
"testing"
"github.com/google/uuid"
"github.com/actforgood/xtransport"
"github.com/actforgood/xtransport/testing/assert"
)
func TestContextWithCorrelationID(t *testing.T) {
t.Parallel()
// arrange
var (
expectedCorrelationID = "test-correlation-foo-bar-123-abc"
ctx = context.Background()
)
// act
defaultCorrelationID := xtransport.CorrelationIDFromContext(ctx)
newCtx := xtransport.ContextWithCorrelationID(ctx, expectedCorrelationID)
actualCorrelationID := xtransport.CorrelationIDFromContext(newCtx)
// assert
assert.Equal(t, "", defaultCorrelationID)
assert.Equal(t, expectedCorrelationID, actualCorrelationID)
}
func TestUUIDCorrelationIDFactory(t *testing.T) {
t.Parallel()
// act
correlationID1 := xtransport.UUIDCorrelationIDFactory()
correlationID2 := xtransport.UUIDCorrelationIDFactory()
// assert
_, err1 := uuid.Parse(correlationID1)
assert.Nil(t, err1)
_, err2 := uuid.Parse(correlationID2)
assert.Nil(t, err2)
assert.True(t, correlationID1 != correlationID2)
}
func TestXRandCorrelationIDFactory(t *testing.T) {
t.Parallel()
// arrange
reg := regexp.MustCompile("^[a-zA-Z0-9]{32}$")
// act
correlationID1 := xtransport.XRandCorrelationIDFactory()
correlationID2 := xtransport.XRandCorrelationIDFactory()
// assert
assert.True(t, reg.MatchString(correlationID1))
assert.True(t, reg.MatchString(correlationID2))
assert.True(t, correlationID1 != correlationID2)
}
func BenchmarkUUIDCorrelationIDFactory(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for range b.N {
_ = xtransport.UUIDCorrelationIDFactory()
}
}
func BenchmarkXRandCorrelationIDFactory(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
for range b.N {
_ = xtransport.XRandCorrelationIDFactory()
}
}