63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package temporal
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestClientConfigDefaults(t *testing.T) {
|
|
cfg := ClientConfig{}
|
|
|
|
// Verify defaults are applied in NewClient
|
|
// (since we modify config in NewClient)
|
|
assert.Equal(t, "", cfg.HostPort)
|
|
assert.Equal(t, "", cfg.Namespace)
|
|
}
|
|
|
|
func TestNewClientConnectionFailure(t *testing.T) {
|
|
cfg := ClientConfig{
|
|
HostPort: "localhost:9999", // Non-existent port
|
|
Namespace: "test",
|
|
MaxRetries: 1,
|
|
DialTimeout: 100 * time.Millisecond,
|
|
}
|
|
|
|
client, err := NewClient(cfg)
|
|
assert.Error(t, err)
|
|
assert.Nil(t, client)
|
|
assert.Contains(t, err.Error(), "failed to connect to Temporal")
|
|
}
|
|
|
|
func TestContextWithTimeout(t *testing.T) {
|
|
ctx, cancel := ContextWithTimeout(5 * time.Second)
|
|
defer cancel()
|
|
|
|
assert.NotNil(t, ctx)
|
|
select {
|
|
case <-ctx.Done():
|
|
t.Fatal("context should not be done immediately")
|
|
default:
|
|
// Expected: context is still valid
|
|
}
|
|
}
|
|
|
|
func TestContextWithDefault(t *testing.T) {
|
|
ctx, cancel := ContextWithDefault()
|
|
defer cancel()
|
|
|
|
assert.NotNil(t, ctx)
|
|
select {
|
|
case <-ctx.Done():
|
|
t.Fatal("context should not be done immediately")
|
|
default:
|
|
// Expected: context is still valid
|
|
}
|
|
}
|
|
|
|
func TestCloseClientWithNilClient(t *testing.T) {
|
|
err := CloseClient(nil)
|
|
assert.NoError(t, err)
|
|
}
|