feat: harden runtime import and frontend verification workflows
This commit is contained in:
57
internal/app/batch_utils_test.go
Normal file
57
internal/app/batch_utils_test.go
Normal file
@@ -0,0 +1,57 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user