Files
zzet--gortex/internal/config/temporal_allowlist_test.go
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

58 lines
1.8 KiB
Go

package config
import (
"os"
"path/filepath"
"sort"
"testing"
)
func writeTemporalAllowlist(t *testing.T, repoPath, body string) {
t.Helper()
dir := filepath.Join(repoPath, ".gortex")
if err := os.MkdirAll(dir, 0o755); err != nil {
t.Fatalf("mkdir: %v", err)
}
if err := os.WriteFile(filepath.Join(dir, "temporal-allowlist.yaml"), []byte(body), 0o644); err != nil {
t.Fatalf("write: %v", err)
}
}
func TestLoadLocalTemporalEnvHelpers_GateOff(t *testing.T) {
dir := t.TempDir()
writeTemporalAllowlist(t, dir, "env_helpers:\n - FetchActivityName\n")
t.Setenv(LocalTemporalOptInEnv, "") // not opted in
if got := LoadLocalTemporalEnvHelpers(dir); got != nil {
t.Fatalf("expected nil without opt-in, got %v", got)
}
}
func TestLoadLocalTemporalEnvHelpers_GateOnReadsFile(t *testing.T) {
dir := t.TempDir()
writeTemporalAllowlist(t, dir, "env_helpers:\n - FetchActivityName\n - GetActivity\n - \"\"\n")
t.Setenv(LocalTemporalOptInEnv, "1")
got := LoadLocalTemporalEnvHelpers(dir)
sort.Strings(got)
want := []string{"FetchActivityName", "GetActivity"}
if len(got) != len(want) || got[0] != want[0] || got[1] != want[1] {
t.Fatalf("got %v, want %v (blank entries dropped)", got, want)
}
}
func TestLoadLocalTemporalEnvHelpers_GateOnNoFile(t *testing.T) {
dir := t.TempDir()
t.Setenv(LocalTemporalOptInEnv, "true")
if got := LoadLocalTemporalEnvHelpers(dir); got != nil {
t.Fatalf("expected nil when file absent, got %v", got)
}
}
func TestLoadLocalTemporalEnvHelpers_GateOnMalformed(t *testing.T) {
dir := t.TempDir()
writeTemporalAllowlist(t, dir, "env_helpers: : not yaml :::\n")
t.Setenv(LocalTemporalOptInEnv, "1")
if got := LoadLocalTemporalEnvHelpers(dir); got != nil {
t.Fatalf("expected nil on malformed file (fail-soft), got %v", got)
}
}