Files
olons_server/internal/store/tasks_test.go
T

38 lines
982 B
Go

package store
import "testing"
func TestJSONInt(t *testing.T) {
tests := []struct {
name string
value any
want int
ok bool
}{
{name: "number", value: float64(900), want: 900, ok: true},
{name: "numeric string", value: "1200", want: 1200, ok: true},
{name: "trimmed numeric string", value: " 900 ", want: 900, ok: true},
{name: "invalid string", value: "15 minutes", ok: false},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, ok := jsonInt(test.value)
if got != test.want || ok != test.ok {
t.Fatalf("jsonInt(%v) = (%d, %v), want (%d, %v)", test.value, got, ok, test.want, test.ok)
}
})
}
}
func TestRandomDelaySeconds(t *testing.T) {
for index := 0; index < 100; index++ {
value := randomDelaySeconds(900, 1200)
if value < 900 || value > 1200 {
t.Fatalf("delay out of range: %d", value)
}
}
if value := randomDelaySeconds(30, 30); value != 30 {
t.Fatalf("fixed delay = %d, want 30", value)
}
}