Files
slogan/styleagent/service/member_service_test.go
T

29 lines
809 B
Go

package service
import (
"testing"
"time"
_ "github.com/gogf/gf/contrib/drivers/sqlite/v2"
"github.com/gogf/gf/v2/os/gtime"
)
func TestNextExpireFromNow(t *testing.T) {
got := NextExpire(nil, 30)
want := time.Now().Add(30 * 24 * time.Hour).Format("2006-01-02 15:04:05")
gotT, _ := time.Parse("2006-01-02 15:04:05", got)
wantT, _ := time.Parse("2006-01-02 15:04:05", want)
if !gotT.Equal(wantT) {
t.Fatalf("过期会员应从现在起算: got=%s want~%s", got, want)
}
}
func TestNextExpireStackOnFuture(t *testing.T) {
base := gtime.NewFromTime(time.Now().Add(10 * 24 * time.Hour))
got := NextExpire(base, 30)
gotT, _ := time.Parse("2006-01-02 15:04:05", got)
if gotT.Before(base.Time) {
t.Fatalf("未过期会员应叠加: got=%s base=%s", got, base.Format("2006-01-02 15:04:05"))
}
}