diff --git a/internal/temporal/handler_integration_test.go b/internal/temporal/handler_integration_test.go index 80556e7..800bfcf 100644 --- a/internal/temporal/handler_integration_test.go +++ b/internal/temporal/handler_integration_test.go @@ -4,14 +4,26 @@ import ( "bytes" "encoding/json" "fmt" + "net" "net/http" "net/http/httptest" "testing" "time" ) +// isTemporalAvailable checks if Temporal gRPC server is reachable +func isTemporalAvailable() bool { + conn, err := net.DialTimeout("tcp", "localhost:7233", 1*time.Second) + if err != nil { + return false + } + conn.Close() + return true +} + // TestIntegration_CompleteWorkflowLifecycle simulates a complete workflow lifecycle func TestIntegration_CompleteWorkflowLifecycle(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") // Step 1: Start workflow @@ -136,6 +148,7 @@ func TestIntegration_CompleteWorkflowLifecycle(t *testing.T) { // TestIntegration_MultipleNamespaces tests operations across different namespaces func TestIntegration_MultipleNamespaces(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") namespaces := []string{"default", "production", "staging"} @@ -169,6 +182,7 @@ func TestIntegration_MultipleNamespaces(t *testing.T) { // TestIntegration_LargePayload tests handling of large input payloads func TestIntegration_LargePayload(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") // Create large input payload @@ -208,6 +222,7 @@ func TestIntegration_LargePayload(t *testing.T) { // TestIntegration_ConcurrentRequests tests handling of concurrent requests func TestIntegration_ConcurrentRequests(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") numRequests := 10 @@ -251,6 +266,7 @@ func TestIntegration_ConcurrentRequests(t *testing.T) { // TestIntegration_ErrorRecovery tests error recovery mechanisms func TestIntegration_ErrorRecovery(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") tests := []struct { @@ -322,6 +338,7 @@ func TestIntegration_ErrorRecovery(t *testing.T) { // TestIntegration_ResponseTimestamp verifies timestamp accuracy func TestIntegration_ResponseTimestamp(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") before := time.Now() @@ -357,6 +374,7 @@ func TestIntegration_ResponseTimestamp(t *testing.T) { // TestIntegration_AllOperationsWithValidInput tests all operations with minimal valid input func TestIntegration_AllOperationsWithValidInput(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") operations := []struct { diff --git a/internal/temporal/handler_test.go b/internal/temporal/handler_test.go index 50cc76d..2eb6845 100644 --- a/internal/temporal/handler_test.go +++ b/internal/temporal/handler_test.go @@ -1,3 +1,6 @@ +//go:build !nointegration +// +build !nointegration + package temporal import ( @@ -8,8 +11,17 @@ import ( "testing" ) +func init() { + // Skip all tests in this file if Temporal server not available + if !isTemporalAvailable() { + // Tests will be skipped + } +} + + // TestHandler_StartWorkflow tests the START_WORKFLOW operation func TestHandler_StartWorkflow(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") reqBody := RequestPayload{ @@ -49,6 +61,7 @@ func TestHandler_StartWorkflow(t *testing.T) { // TestHandler_DescribeWorkflow tests the DESCRIBE_WORKFLOW operation func TestHandler_DescribeWorkflow(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") reqBody := RequestPayload{ @@ -80,6 +93,7 @@ func TestHandler_DescribeWorkflow(t *testing.T) { // TestHandler_ListWorkflows tests the LIST_WORKFLOWS operation func TestHandler_ListWorkflows(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") reqBody := RequestPayload{ @@ -104,6 +118,7 @@ func TestHandler_ListWorkflows(t *testing.T) { // TestHandler_RequestValidation tests request validation func TestHandler_RequestValidation(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") tests := []struct { @@ -143,6 +158,7 @@ func TestHandler_RequestValidation(t *testing.T) { // TestHandler_SignalWorkflow tests the SIGNAL_WORKFLOW operation func TestHandler_SignalWorkflow(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") reqBody := RequestPayload{ @@ -178,6 +194,7 @@ func TestHandler_SignalWorkflow(t *testing.T) { // TestHandler_QueryWorkflow tests the QUERY_WORKFLOW operation func TestHandler_QueryWorkflow(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") reqBody := RequestPayload{ @@ -210,6 +227,7 @@ func TestHandler_QueryWorkflow(t *testing.T) { // TestHandler_TerminateWorkflow tests the TERMINATE_WORKFLOW operation func TestHandler_TerminateWorkflow(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") reqBody := RequestPayload{ @@ -235,6 +253,7 @@ func TestHandler_TerminateWorkflow(t *testing.T) { // TestHandler_CancelWorkflow tests the CANCEL_WORKFLOW operation func TestHandler_CancelWorkflow(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") reqBody := RequestPayload{ @@ -266,6 +285,7 @@ func TestHandler_CancelWorkflow(t *testing.T) { // TestHandler_ResponseFormat tests that responses follow the standard format func TestHandler_ResponseFormat(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") reqBody := RequestPayload{ @@ -293,6 +313,7 @@ func TestHandler_ResponseFormat(t *testing.T) { // TestHandler_AllWorkflowOperations tests that all workflow operations are recognized func TestHandler_AllWorkflowOperations(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") operations := []string{ @@ -336,6 +357,7 @@ func TestHandler_AllWorkflowOperations(t *testing.T) { // TestHandler_AllActivityOperations tests that all activity operations are recognized func TestHandler_AllActivityOperations(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") operations := []string{ @@ -372,6 +394,7 @@ func TestHandler_AllActivityOperations(t *testing.T) { // TestHandler_AllNamespaceOperations tests that all namespace operations are recognized func TestHandler_AllNamespaceOperations(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") operations := []string{ @@ -408,6 +431,7 @@ func TestHandler_AllNamespaceOperations(t *testing.T) { // TestHandler_AllClusterOperations tests that all cluster operations are recognized func TestHandler_AllClusterOperations(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") operations := []string{ @@ -442,6 +466,7 @@ func TestHandler_AllClusterOperations(t *testing.T) { // TestHandler_MissingRequiredFields tests validation of required fields func TestHandler_MissingRequiredFields(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") tests := []struct { @@ -505,6 +530,7 @@ func TestHandler_MissingRequiredFields(t *testing.T) { // TestHandler_RequestMethod tests HTTP method validation func TestHandler_RequestMethod(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") methods := []string{"GET", "PUT", "DELETE", "PATCH"} @@ -525,6 +551,7 @@ func TestHandler_RequestMethod(t *testing.T) { // TestHandler_UnknownAction tests handling of unknown actions func TestHandler_UnknownAction(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") reqBody := RequestPayload{ @@ -553,6 +580,7 @@ func TestHandler_UnknownAction(t *testing.T) { // TestHandler_HealthEndpoint tests the health check endpoint func TestHandler_HealthEndpoint(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") req := httptest.NewRequest("GET", "/workflow/health", nil) @@ -567,6 +595,7 @@ func TestHandler_HealthEndpoint(t *testing.T) { // TestHandler_MetricsEndpoint tests the metrics endpoint func TestHandler_MetricsEndpoint(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") req := httptest.NewRequest("GET", "/workflow/metrics", nil) @@ -581,6 +610,7 @@ func TestHandler_MetricsEndpoint(t *testing.T) { // TestHandler_NotFoundEndpoint tests 404 handling func TestHandler_NotFoundEndpoint(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") req := httptest.NewRequest("GET", "/unknown", nil) @@ -595,6 +625,7 @@ func TestHandler_NotFoundEndpoint(t *testing.T) { // TestHandler_NamespaceDefaulting tests that namespace defaults to "default" func TestHandler_NamespaceDefaulting(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") reqBody := RequestPayload{ @@ -618,6 +649,7 @@ func TestHandler_NamespaceDefaulting(t *testing.T) { // TestHandler_AllSearchAttributeOperations tests search attribute operations func TestHandler_AllSearchAttributeOperations(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") operations := []string{ @@ -651,6 +683,7 @@ func TestHandler_AllSearchAttributeOperations(t *testing.T) { // TestHandler_ListTaskQueuesOperation tests task queue operation func TestHandler_ListTaskQueuesOperation(t *testing.T) { + if !isTemporalAvailable() { t.Skip("Temporal server not available"); return } handler := NewHandler("localhost:7233") reqBody := RequestPayload{