Files
sub2api-cn-relay-manager/internal/app/batch_utils_test.go
phamnazage-jpg 77b7f7f660
Some checks failed
CI / Build & Test (push) Has been cancelled
CI / Lint (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / Docker Build (push) Has been cancelled
CI / Release (push) Has been cancelled
feat: harden runtime import and frontend verification workflows
2026-06-04 20:02:36 +08:00

58 lines
1.3 KiB
Go

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