Files
poimen-workflows/internal/temporal/client_test.go
T
poimen dde7f7f37e
CI / CI (pull_request) Successful in 4m32s
feat(phase-1.2): temporal SDK client, worker mgmt, k8s deployments
- internal/temporal/client.go: robust client with retry + TLS + health check
- internal/temporal/worker.go: worker creation, registration, lifecycle
- internal/temporal/context.go: timeout helpers
- k8s/worker-deployment.yaml: 2-10 replica HPA, health probes, security context
- k8s/workflow-runner-deployment.yaml: singleton runner with probes
- k8s/kustomization.yaml: updated resource list, removed missing ref

Tests: 11 pass (client_test.go + worker_test.go)
Build: go build ./... clean
Kustomize: dry-run validated
2026-09-08 16:28:53 -07:00

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)
}