47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package user
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestComputeExpiry_NewYearly(t *testing.T) {
|
|
now := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)
|
|
exp := computeExpiry(SubYearly, 1, time.Time{}, now)
|
|
if exp == nil {
|
|
t.Fatal("nil expiry")
|
|
}
|
|
want := now.AddDate(1, 0, 0)
|
|
if !exp.Equal(want) {
|
|
t.Errorf("got %v want %v", exp, want)
|
|
}
|
|
}
|
|
|
|
func TestComputeExpiry_RenewActive(t *testing.T) {
|
|
now := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)
|
|
current := now.AddDate(0, 6, 0)
|
|
exp := computeExpiry(SubYearly, 1, current, now)
|
|
want := current.AddDate(1, 0, 0)
|
|
if !exp.Equal(want) {
|
|
t.Errorf("active renew: got %v want %v", exp, want)
|
|
}
|
|
}
|
|
|
|
func TestComputeExpiry_RenewExpired(t *testing.T) {
|
|
now := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)
|
|
past := now.AddDate(0, -1, 0)
|
|
exp := computeExpiry(SubYearly, 1, past, now)
|
|
want := now.AddDate(1, 0, 0)
|
|
if !exp.Equal(want) {
|
|
t.Errorf("expired renew: got %v want %v", exp, want)
|
|
}
|
|
}
|
|
|
|
func TestComputeExpiry_Lifetime(t *testing.T) {
|
|
now := time.Now()
|
|
exp := computeExpiry(SubLifetime, 1, time.Time{}, now)
|
|
if exp != nil {
|
|
t.Errorf("lifetime should be nil, got %v", exp)
|
|
}
|
|
}
|