2024-05-17 18:30:33 +08:00
|
|
|
// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
2022-11-26 11:05:46 +08:00
|
|
|
|
|
|
|
|
package caches_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/TeaOSLab/EdgeNode/internal/caches"
|
2024-04-18 18:25:33 +08:00
|
|
|
"github.com/cespare/xxhash/v2"
|
2022-11-26 11:05:46 +08:00
|
|
|
"github.com/iwind/TeaGo/types"
|
|
|
|
|
"strconv"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestParseHost(t *testing.T) {
|
|
|
|
|
for _, u := range []string{
|
|
|
|
|
"https://goedge.cn/hello/world",
|
|
|
|
|
"https://goedge.cn:8080/hello/world",
|
|
|
|
|
"https://goedge.cn/hello/world?v=1&t=123",
|
|
|
|
|
"https://[::1]:1234/hello/world?v=1&t=123",
|
|
|
|
|
"https://[::1]/hello/world?v=1&t=123",
|
|
|
|
|
"https://127.0.0.1/hello/world?v=1&t=123",
|
|
|
|
|
"https:/hello/world?v=1&t=123",
|
|
|
|
|
"123456",
|
|
|
|
|
} {
|
|
|
|
|
t.Log(u, "=>", caches.ParseHost(u))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestUintString(t *testing.T) {
|
|
|
|
|
t.Log(strconv.FormatUint(xxhash.Sum64String("https://goedge.cn/"), 10))
|
|
|
|
|
t.Log(strconv.FormatUint(123456789, 10))
|
2023-08-08 12:02:21 +08:00
|
|
|
t.Logf("%d", 1234567890123)
|
2022-11-26 11:05:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BenchmarkUint_String(b *testing.B) {
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
|
_ = strconv.FormatUint(1234567890123, 10)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BenchmarkUint_String2(b *testing.B) {
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
|
_ = types.String(1234567890123)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BenchmarkUint_String3(b *testing.B) {
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
|
_ = fmt.Sprintf("%d", 1234567890123)
|
|
|
|
|
}
|
|
|
|
|
}
|