ip_test.go 648 B

123456789101112131415161718192021222324252627
  1. package network_test
  2. import (
  3. "testing"
  4. "github.com/labring/aiproxy/core/common/network"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestIsIpInSubnet(t *testing.T) {
  8. ip1 := "192.168.0.5"
  9. ip2 := "125.216.250.89"
  10. subnet := "192.168.0.0/24"
  11. convey.Convey("TestIsIpInSubnet", t, func() {
  12. if ok, err := network.IsIPInSubnet(ip1, subnet); err != nil {
  13. t.Errorf("failed to check ip in subnet: %s", err)
  14. } else {
  15. convey.So(ok, convey.ShouldBeTrue)
  16. }
  17. if ok, err := network.IsIPInSubnet(ip2, subnet); err != nil {
  18. t.Errorf("failed to check ip in subnet: %s", err)
  19. } else {
  20. convey.So(ok, convey.ShouldBeFalse)
  21. }
  22. })
  23. }