Skip to content

Commit

Permalink
- Package Moving
Browse files Browse the repository at this point in the history
  • Loading branch information
joeavanzato committed Dec 28, 2023
1 parent 29705ac commit c9510b0
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions network_test.go → helpers/network_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main
package helpers

import (
"github.com/joeavanzato/logboost/helpers"
"net"
"testing"
)
Expand All @@ -10,37 +9,37 @@ import (

func TestSetupPrivateNetworks(t *testing.T) {
want := 12
err := helpers.SetupPrivateNetworks()
err := SetupPrivateNetworks()
if err != nil {
t.Fatalf(`Error setupPrivateNetworks: %v`, err)
}
if len(helpers.PrivateIPBlocks) != want {
t.Fatalf(`Error setupPrivateNetworks - wanted %v, got %v`, want, len(helpers.PrivateIPBlocks))
if len(PrivateIPBlocks) != want {
t.Fatalf(`Error setupPrivateNetworks - wanted %v, got %v`, want, len(PrivateIPBlocks))
}
}

func TestIsPrivateIP(t *testing.T) {
// TODO - Add more IPv4/IPv6 tests to each
privateIPs := []string{"127.0.0.1", "192.168.3.5", "172.16.2.3", "255.255.255.255", "fe80::ffff:ffff:ffff:ffff", "::1", "fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "64:ff9b:1:ffff:ffff:ffff:ffff:ffcf"}
for _, v := range privateIPs {
if !helpers.IsPrivateIP(net.ParseIP(v), v) {
if !IsPrivateIP(net.ParseIP(v), v) {
t.Fatalf(`Error isPrivateIP: wanted true, got false for value: %v`, v)
}
}
publicIPs := []string{"8.8.8.8", "32.3.54.1", "1.1.1.1", "2002:ffff:ffff:ffff:ffff:ffff:ffff:ffcf", "2001::ffff:ffff:ffff:ffff:ffff:fcff"}
for _, v := range publicIPs {
if helpers.IsPrivateIP(net.ParseIP(v), v) {
if IsPrivateIP(net.ParseIP(v), v) {
t.Fatalf(`Error isPrivateIP: wanted false, got true for value: %v`, v)
}
}
}

func TestLookupIP(t *testing.T) {
results := helpers.LookupIPRecords("8.8.8.8")
results := LookupIPRecords("8.8.8.8")
if len(results) != 1 {
t.Fatalf(`Error lookupIPRecords - wanted 1, got %v`, len(results))
}
newresults := helpers.LookupIPRecords("non-existent")
newresults := LookupIPRecords("non-existent")
if len(newresults) != 1 {
t.Fatalf(`Error lookupIPRecords - wanted 0, got %v`, len(newresults))
}
Expand Down

0 comments on commit c9510b0

Please sign in to comment.