Apply .gitignore rules
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
module admincenter
|
||||
|
||||
go 1.22.10
|
||||
|
||||
replace (
|
||||
common => ../common
|
||||
framework => ../framework
|
||||
goutil => ../goutil
|
||||
)
|
||||
|
||||
require (
|
||||
common v0.0.0-00010101000000-000000000000
|
||||
goutil v0.0.0-20230425160006-b2d0b0a0b0b0
|
||||
)
|
||||
|
||||
require (
|
||||
filippo.io/edwards25519 v1.1.0 // indirect
|
||||
framework v0.0.0-20230425160006-b2d0b0a0b0b0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/elastic/go-elasticsearch/v8 v8.0.0-20210916085751-c2fb55d91ba4 // indirect
|
||||
github.com/fatih/color v1.15.0 // indirect
|
||||
github.com/go-redis/redis/v8 v8.11.5 // indirect
|
||||
github.com/go-sql-driver/mysql v1.8.1 // indirect
|
||||
github.com/gomodule/redigo v1.8.9 // indirect
|
||||
github.com/gorilla/websocket v1.4.2 // indirect
|
||||
github.com/jinzhu/gorm v1.9.12 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8 // indirect
|
||||
golang.org/x/sys v0.6.0 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
|
||||
gorm.io/driver/mysql v1.5.7 // indirect
|
||||
gorm.io/gorm v1.25.12 // indirect
|
||||
)
|
||||
@@ -0,0 +1,136 @@
|
||||
package idUtil
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewTimeIdentifierSeedGenerator(t *testing.T) {
|
||||
generator, err := NewTimeIdentifierSeedGenerator(40, 1, 7, 20)
|
||||
if err == nil {
|
||||
t.Errorf("there should be err, but now not.")
|
||||
}
|
||||
|
||||
generator, err = NewTimeIdentifierSeedGenerator(10, int64(1), 7, 20)
|
||||
if err != nil {
|
||||
t.Errorf("there should be no err, but now there is.")
|
||||
}
|
||||
_, err = generator.GenerateNewId()
|
||||
if err == nil {
|
||||
t.Errorf("there should be err, but now not.")
|
||||
}
|
||||
|
||||
generator, err = NewTimeIdentifierSeedGenerator(40, int64(127), 3, 20)
|
||||
if err == nil {
|
||||
t.Errorf("there should be err, but now not.")
|
||||
}
|
||||
|
||||
count := 1048575
|
||||
idMap := make(map[int64]struct{}, count)
|
||||
for identifier := 0; identifier < 8; identifier++ {
|
||||
generator, err = NewTimeIdentifierSeedGenerator(40, int64(identifier), 3, 20)
|
||||
if err != nil {
|
||||
t.Errorf("There should be no error, but now there is:%s", err)
|
||||
return
|
||||
}
|
||||
|
||||
for i := 0; i < count; i++ {
|
||||
id, err := generator.GenerateNewId()
|
||||
if err != nil {
|
||||
t.Errorf("There should be no error, but now there is:%s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if _, exist := idMap[id]; exist {
|
||||
t.Errorf("Id:%d is duplicated.", id)
|
||||
return
|
||||
}
|
||||
|
||||
idMap[id] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewIdentifierTimeSeedGenerator(t *testing.T) {
|
||||
generator, err := NewIdentifierTimeSeedGenerator(int64(1), 7, 40, 20)
|
||||
if err == nil {
|
||||
t.Errorf("there should be err, but now not.")
|
||||
}
|
||||
|
||||
generator, err = NewIdentifierTimeSeedGenerator(int64(1), 7, 10, 20)
|
||||
if err != nil {
|
||||
t.Errorf("there should be no err, but now there is.")
|
||||
}
|
||||
_, err = generator.GenerateNewId()
|
||||
if err == nil {
|
||||
t.Errorf("there should be err, but now not.")
|
||||
}
|
||||
|
||||
generator, err = NewIdentifierTimeSeedGenerator(int64(127), 3, 40, 20)
|
||||
if err == nil {
|
||||
t.Errorf("there should be err, but now not.")
|
||||
}
|
||||
|
||||
count := 1048575
|
||||
idMap := make(map[int64]struct{}, count)
|
||||
for identifier := 0; identifier < 8; identifier++ {
|
||||
generator, err = NewIdentifierTimeSeedGenerator(int64(identifier), 3, 40, 20)
|
||||
if err != nil {
|
||||
t.Errorf("There should be no error, but now there is:%s", err)
|
||||
return
|
||||
}
|
||||
|
||||
for i := 0; i < count; i++ {
|
||||
id, err := generator.GenerateNewId()
|
||||
if err != nil {
|
||||
t.Errorf("There should be no error, but now there is:%s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if _, exist := idMap[id]; exist {
|
||||
t.Errorf("Id:%d is duplicated.", id)
|
||||
return
|
||||
}
|
||||
|
||||
idMap[id] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewIdentifierConstructCountSeedGenerator(t *testing.T) {
|
||||
generator, err := NewIdentifierConstructCountSeedGenerator(int64(1), 27, int64(1), 20, 23)
|
||||
if err == nil {
|
||||
t.Errorf("there should be err, but now not.")
|
||||
}
|
||||
|
||||
generator, err = NewIdentifierConstructCountSeedGenerator(int64(32768), 15, int64(1), 18, 30)
|
||||
if err == nil {
|
||||
t.Errorf("there should be err, but now not.")
|
||||
}
|
||||
|
||||
count := 1048575
|
||||
idMap := make(map[int64]struct{}, count)
|
||||
for identifier := 0; identifier < 8; identifier++ {
|
||||
for constructCount := 0; constructCount < 5; constructCount++ {
|
||||
generator, err = NewIdentifierConstructCountSeedGenerator(int64(identifier), 15, int64(constructCount), 18, 30)
|
||||
if err != nil {
|
||||
t.Errorf("There should be no error, but now there is:%s", err)
|
||||
return
|
||||
}
|
||||
|
||||
for i := 0; i < count; i++ {
|
||||
id, err := generator.GenerateNewId()
|
||||
if err != nil {
|
||||
t.Errorf("There should be no error, but now there is:%s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if _, exist := idMap[id]; exist {
|
||||
t.Errorf("Id:%d is duplicated.", id)
|
||||
return
|
||||
}
|
||||
|
||||
idMap[id] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package zlibUtil
|
||||
|
||||
import (
|
||||
"compress/zlib"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
InitString = `{"Code":4,"Message":"IPNotAuthorized","Data":null}`
|
||||
CompressBytes []byte
|
||||
)
|
||||
|
||||
func TestCompress(t *testing.T) {
|
||||
data := ([]byte)(InitString)
|
||||
result, _ := Compress(data, zlib.DefaultCompression)
|
||||
// if isEqual(result, CompressBytes) == false {
|
||||
// t.Errorf("压缩失败,期待%v,实际%v", InitBytes, result)
|
||||
// }
|
||||
|
||||
CompressBytes = result
|
||||
}
|
||||
|
||||
func TestDecompress(t *testing.T) {
|
||||
data, _ := Decompress(CompressBytes)
|
||||
result := string(data)
|
||||
if result != InitString {
|
||||
t.Errorf("解压缩失败,期待%s,实际%s", InitString, result)
|
||||
}
|
||||
}
|
||||
|
||||
func isEqual(a, b []byte) bool {
|
||||
if a == nil && b == nil {
|
||||
return true
|
||||
} else if a == nil || b == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := 0; i < len(a); i++ {
|
||||
if a[i] != b[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
//BenchmarkCompress-12 10989 107509 ns/op
|
||||
func BenchmarkCompress(b *testing.B) {
|
||||
toCompress := []byte(strings.Repeat(InitString, 100))
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_,err :=Compress(toCompress, zlib.DefaultCompression)
|
||||
if err!=nil{
|
||||
b.Log(err)
|
||||
}
|
||||
}
|
||||
b.StopTimer()
|
||||
}
|
||||
|
||||
//BenchmarkDeCompress-12 99153 10802 ns/op
|
||||
func BenchmarkDeCompress(b *testing.B) {
|
||||
toCompress := []byte(strings.Repeat(InitString, 100))
|
||||
compressedData,_ := Compress(toCompress, zlib.DefaultCompression)
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_,err := Decompress(compressedData)
|
||||
if err!=nil{
|
||||
b.Log(err)
|
||||
}
|
||||
}
|
||||
b.StopTimer()
|
||||
}
|
||||
Reference in New Issue
Block a user