nezha/pkg/utils/utils_test.go

59 lines
1.2 KiB
Go
Raw Normal View History

2021-05-27 08:48:12 -04:00
package utils
import (
"testing"
)
type testSt struct {
input string
output string
}
func TestNotification(t *testing.T) {
cases := []testSt{
{
input: "103.80.236.249/d5ce:d811:cdb8:067a:a873:2076:9521:9d2d",
output: "103.****.249/d5ce:d811:****:9521:9d2d",
2021-05-27 08:48:12 -04:00
},
{
input: "3.80.236.29/d5ce::cdb8:067a:a873:2076:9521:9d2d",
output: "3.****.29/d5ce::****:9521:9d2d",
2021-05-27 08:48:12 -04:00
},
{
input: "3.80.236.29/d5ce::cdb8:067a:a873:2076::9d2d",
output: "3.****.29/d5ce::****::9d2d",
2021-05-27 08:48:12 -04:00
},
{
input: "3.80.236.9/d5ce::cdb8:067a:a873:2076::9d2d",
output: "3.****.9/d5ce::****::9d2d",
2021-05-27 08:48:12 -04:00
},
{
input: "3.80.236.9/d5ce::cdb8:067a:a873:2076::9d2d",
output: "3.****.9/d5ce::****::9d2d",
2021-05-27 08:48:12 -04:00
},
}
for _, c := range cases {
if c.output != IPDesensitize(c.input) {
t.Fatalf("Expected %s, but got %s", c.output, IPDesensitize(c.input))
}
2021-05-27 08:48:12 -04:00
}
}
2022-12-16 10:34:14 -05:00
func TestGenerGenerateRandomString(t *testing.T) {
generatedString := make(map[string]bool)
for i := 0; i < 100; i++ {
str, err := GenerateRandomString(32)
if err != nil {
t.Fatalf("Error: %s", err)
}
if len(str) != 32 {
t.Fatalf("Expected 32, but got %d", len(str))
}
if generatedString[str] {
t.Fatalf("Duplicated string: %s", str)
}
2022-12-16 10:34:14 -05:00
generatedString[str] = true
}
}