-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient_test.go
More file actions
77 lines (63 loc) · 1.74 KB
/
client_test.go
File metadata and controls
77 lines (63 loc) · 1.74 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
package temporal
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"github.com/jasoet/pkg/v2/otel"
)
func TestConfigWithOTelConfig(t *testing.T) {
t.Run("NilOTelConfig", func(t *testing.T) {
config := &Config{
HostPort: "localhost:7233",
Namespace: "default",
OTelConfig: nil,
}
assert.Nil(t, config.OTelConfig)
})
t.Run("WithOTelConfig", func(t *testing.T) {
tp := sdktrace.NewTracerProvider()
defer func() { _ = tp.Shutdown(nil) }()
otelCfg := &otel.Config{
TracerProvider: tp,
}
config := &Config{
HostPort: "localhost:7233",
Namespace: "default",
OTelConfig: otelCfg,
}
require.NotNil(t, config.OTelConfig)
assert.True(t, config.OTelConfig.IsTracingEnabled())
})
t.Run("DefaultConfigHasNilOTelConfig", func(t *testing.T) {
config := DefaultConfig()
assert.Nil(t, config.OTelConfig)
})
}
func TestNewClient_NilOTelConfig(t *testing.T) {
// When OTelConfig is nil, NewClient should not panic.
// The client creation will fail due to invalid host, but the OTel
// interceptor path should be skipped gracefully.
config := &Config{
HostPort: "invalid-host-that-does-not-exist:7233",
Namespace: "default",
OTelConfig: nil,
}
// This may or may not error (Temporal client.Dial is lazy), but it must not panic
c, _ := NewClient(config)
if c != nil {
c.Close()
}
}
func TestNewClient_OTelConfigTracingDisabled(t *testing.T) {
// OTelConfig with no TracerProvider => tracing disabled => interceptor not added
config := &Config{
HostPort: "invalid-host-that-does-not-exist:7233",
Namespace: "default",
OTelConfig: &otel.Config{},
}
c, _ := NewClient(config)
if c != nil {
c.Close()
}
}