package app import ( "context" "testing" "time" ) // Test utility functions from batch_runtime.go func TestSleepWithContext_Normal(t *testing.T) { ctx := context.Background() start := time.Now() err := sleepWithContext(ctx, 1*time.Millisecond) elapsed := time.Since(start) if err != nil { t.Errorf("sleep should not error: %v", err) } if elapsed < 1*time.Millisecond { t.Error("should have slept") } } func TestSleepWithContext_Canceled(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() start := time.Now() err := sleepWithContext(ctx, 100*time.Millisecond) elapsed := time.Since(start) if err == nil { t.Error("canceled context should return error") } if elapsed > 10*time.Millisecond { t.Error("should have returned early due to cancellation") } } func TestFirstNonEmptyString(t *testing.T) { if firstNonEmptyString("", "", "value") != "value" { t.Error("should return first non-empty") } } func TestFirstNonEmptyString_First(t *testing.T) { if firstNonEmptyString("first", "second", "third") != "first" { t.Error("should return first value when all non-empty") } } func TestFirstNonEmptyString_AllEmpty(t *testing.T) { if firstNonEmptyString("", "", "") != "" { t.Error("all empty should return empty") } }