2024-05-17 18:28:59 +08:00
|
|
|
// Copyright 2021 GoEdge CDN goedge.cdn@gmail.com. All rights reserved.
|
2021-08-19 10:50:40 +08:00
|
|
|
|
2022-06-28 20:26:44 +08:00
|
|
|
package configutils_test
|
2021-08-19 10:50:40 +08:00
|
|
|
|
2022-06-28 20:26:44 +08:00
|
|
|
import (
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
|
|
|
|
"github.com/iwind/TeaGo/assert"
|
|
|
|
|
"net"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
2021-08-19 10:50:40 +08:00
|
|
|
|
2022-06-28 20:26:44 +08:00
|
|
|
func TestIsIPv4(t *testing.T) {
|
|
|
|
|
t.Log(configutils.IsIPv4(net.ParseIP("192.168.1.100")))
|
|
|
|
|
t.Log(configutils.IsIPv4(net.ParseIP("::1")))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestIsIPv6(t *testing.T) {
|
|
|
|
|
t.Log(configutils.IsIPv6(net.ParseIP("192.168.1.100")))
|
|
|
|
|
t.Log(configutils.IsIPv6(net.ParseIP("::1")))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestIPVersion(t *testing.T) {
|
|
|
|
|
var a = assert.NewAssertion(t)
|
|
|
|
|
a.IsTrue(configutils.IPVersion(net.ParseIP("192.168.1.100")) == 4)
|
|
|
|
|
a.IsTrue(configutils.IPVersion(net.ParseIP("1.2.3")) == 0)
|
|
|
|
|
a.IsTrue(configutils.IPVersion(net.ParseIP("::1")) == 6)
|
|
|
|
|
a.IsTrue(configutils.IPVersion(net.ParseIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334")) == 6)
|
2021-08-19 10:50:40 +08:00
|
|
|
}
|
2023-06-02 14:58:08 +08:00
|
|
|
|
|
|
|
|
func TestQuoteIP(t *testing.T) {
|
|
|
|
|
t.Log(configutils.QuoteIP(configutils.QuoteIP("2001:da8:22::10")))
|
2024-04-06 09:12:17 +08:00
|
|
|
}
|