| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 | package licenseimport (	"fmt"	"math/rand/v2"	"testing"	"time")// 标准输出func TestLicenseNewStandard(t *testing.T) {	date := time.Now().AddDate(0, 0, 2)	curY, curM, curD := date.Date()	expiration := time.Date(curY, curM, curD, 23, 59, 59, 0, time.Local)	encryptedKey, err := New(expiration)	if err != nil {		t.Error(err)		return	}	fmt.Println("许可密钥:", encryptedKey)	info, err := Stat(encryptedKey)	if err != nil {		t.Error(err)		return	}	rand.Int()	fmt.Println("创建时间:", info.CreateAt().Format(time.DateTime))	fmt.Println("过期时间:", info.ExpireAt().Format(time.DateTime))}// 标准输出, 自定义日期func TestLicenseNewWithCustom(t *testing.T) {	expiration := time.Date(2024, 10, 16, 23, 59, 59, 0, time.Local)	encryptedKey, err := New(expiration)	if err != nil {		t.Error(err)		return	}	fmt.Println("许可密钥:", encryptedKey)	info, err := Stat(encryptedKey)	if err != nil {		t.Error(err)		return	}	rand.Int()	fmt.Println("创建时间:", info.CreateAt().Format(time.DateTime))	fmt.Println("过期时间:", info.ExpireAt().Format(time.DateTime))}// 永久授权输出func TestPerpetualLicenseNew(t *testing.T) {	expiration := time.Date(9999, 12, 31, 23, 59, 59, 0, time.Local)	encryptedKey, err := New(expiration)	if err != nil {		t.Error(err)		return	}	fmt.Println("许可密钥:", encryptedKey)	info, err := Stat(encryptedKey)	if err != nil {		t.Error(err)		return	}	fmt.Println("创建时间:", info.CreateAt().Format(time.DateTime))	fmt.Println("过期时间:", info.ExpireAt().Format(time.DateTime))}func TestLicense_New(t *testing.T) {	d, err := time.ParseDuration("+1m")	if err != nil {		t.Fatal(err)		return	}	expiration := time.Now().Add(d)	// expiration := time.Now().AddDate(0, 0, 1)	encryptedKey, err := New(expiration)	if err != nil {		t.Error(err)		return	}	t.Log("密钥长度:", len(encryptedKey))	t.Log("许可密钥:", encryptedKey)	info, err := Stat(encryptedKey)	if err != nil {		t.Error(err)		return	}	t.Log("创建时间:", info.CreateAt().Format(time.DateTime))	t.Log("过期时间:", info.ExpireAt().Format(time.DateTime))	// 检查有效期	if info.Expired() {		t.Logf("License has expired on: %s", info.ExpireAt())	} else {		t.Logf("License expire in %s", info.ExpireAt())	}}
 |