forked from molecule-ai/molecule-core
Forked clean from public hackathon repo (Starfire-AgentTeam, BSL 1.1) with full rebrand to Molecule AI under github.com/Molecule-AI/molecule-monorepo. Brand: Starfire → Molecule AI. Slug: starfire / agent-molecule → molecule. Env vars: STARFIRE_* → MOLECULE_*. Go module: github.com/agent-molecule/platform → github.com/Molecule-AI/molecule-monorepo/platform. Python packages: starfire_plugin → molecule_plugin, starfire_agent → molecule_agent. DB: agentmolecule → molecule. History truncated; see public repo for prior commits and contributor attribution. Verified green: go test -race ./... (platform), pytest (workspace-template 1129 + sdk 132), vitest (canvas 352), build (mcp). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
package envx
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestDuration(t *testing.T) {
|
|
const key = "__envx_test_duration"
|
|
t.Run("unset uses default", func(t *testing.T) {
|
|
t.Setenv(key, "")
|
|
if got := Duration(key, 42*time.Second); got != 42*time.Second {
|
|
t.Errorf("want default, got %v", got)
|
|
}
|
|
})
|
|
t.Run("valid value parsed", func(t *testing.T) {
|
|
t.Setenv(key, "30s")
|
|
if got := Duration(key, time.Second); got != 30*time.Second {
|
|
t.Errorf("want 30s, got %v", got)
|
|
}
|
|
})
|
|
t.Run("unparseable falls back", func(t *testing.T) {
|
|
t.Setenv(key, "not-a-duration")
|
|
if got := Duration(key, 5*time.Second); got != 5*time.Second {
|
|
t.Errorf("want default, got %v", got)
|
|
}
|
|
})
|
|
t.Run("zero falls back", func(t *testing.T) {
|
|
t.Setenv(key, "0")
|
|
if got := Duration(key, 5*time.Second); got != 5*time.Second {
|
|
t.Errorf("want default, got %v", got)
|
|
}
|
|
})
|
|
t.Run("negative falls back", func(t *testing.T) {
|
|
t.Setenv(key, "-1h")
|
|
if got := Duration(key, 5*time.Second); got != 5*time.Second {
|
|
t.Errorf("want default, got %v", got)
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestInt64(t *testing.T) {
|
|
const key = "__envx_test_int64"
|
|
t.Run("unset uses default", func(t *testing.T) {
|
|
t.Setenv(key, "")
|
|
if got := Int64(key, 99); got != 99 {
|
|
t.Errorf("want default, got %d", got)
|
|
}
|
|
})
|
|
t.Run("valid value parsed", func(t *testing.T) {
|
|
t.Setenv(key, "123")
|
|
if got := Int64(key, 1); got != 123 {
|
|
t.Errorf("want 123, got %d", got)
|
|
}
|
|
})
|
|
t.Run("unparseable falls back", func(t *testing.T) {
|
|
t.Setenv(key, "nope")
|
|
if got := Int64(key, 5); got != 5 {
|
|
t.Errorf("want default, got %d", got)
|
|
}
|
|
})
|
|
t.Run("zero falls back", func(t *testing.T) {
|
|
t.Setenv(key, "0")
|
|
if got := Int64(key, 5); got != 5 {
|
|
t.Errorf("want default, got %d", got)
|
|
}
|
|
})
|
|
t.Run("negative falls back", func(t *testing.T) {
|
|
t.Setenv(key, "-10")
|
|
if got := Int64(key, 5); got != 5 {
|
|
t.Errorf("want default, got %d", got)
|
|
}
|
|
})
|
|
}
|