tulip/red-server/server_test.go

39 lines
1.5 KiB
Go
Raw Normal View History

2024-01-29 10:44:45 +00:00
package red_server
2023-09-24 18:24:16 +01:00
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestParseClaims(t *testing.T) {
assert.Equal(t, map[string]bool{"openid": true, "email": true}, ParseClaims("openid email"))
assert.Equal(t, map[string]bool{"openid": true, "profile": true, "email": true}, ParseClaims("openid profile email"))
assert.Equal(t, map[string]bool{"openid": true, "email": true}, ParseClaims("openid email "))
assert.Equal(t, map[string]bool{"openid": true, "email": true}, ParseClaims(" openid email"))
assert.Equal(t, map[string]bool{"openid": true, "profile": true, "email": true}, ParseClaims(" openid profile email "))
}
func TestCalculateAge(t *testing.T) {
lGmt := time.FixedZone("GMT", 0)
lBst := time.FixedZone("BST", 60*60)
tPast := time.Date(1939, time.January, 5, 0, 0, 0, 0, lGmt)
tPastDst := time.Date(2001, time.January, 5, 1, 0, 0, 0, lBst)
tCur := time.Date(2005, time.January, 5, 0, 30, 0, 0, lGmt)
tCurDst := time.Date(2005, time.January, 5, 0, 30, 0, 0, lBst)
tFut := time.Date(2008, time.January, 5, 0, 0, 0, 0, time.UTC)
ageTimeNow = func() time.Time { return tCur }
assert.Equal(t, 65, CalculateAge(tPast))
assert.Equal(t, 3, CalculateAge(tPastDst))
assert.Equal(t, 0, CalculateAge(tFut))
ageTimeNow = func() time.Time { return tCurDst }
assert.Equal(t, 66, CalculateAge(tPast))
assert.Equal(t, 4, CalculateAge(tPastDst))
fmt.Println(tPastDst.AddDate(4, 0, 0).UTC(), tCur.UTC())
assert.Equal(t, 0, CalculateAge(tFut))
}