diff options
Diffstat (limited to 'adapters/netscan/netscan_test.go')
| -rw-r--r-- | adapters/netscan/netscan_test.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/adapters/netscan/netscan_test.go b/adapters/netscan/netscan_test.go new file mode 100644 index 0000000..b50ef0c --- /dev/null +++ b/adapters/netscan/netscan_test.go @@ -0,0 +1,33 @@ +package netscan + +import ( + "reflect" + "testing" +) + +func TestHostIPs(t *testing.T) { + ips, err := hostIPs("192.168.1.0/30") + if err != nil { + t.Fatal(err) + } + if want := []string{"192.168.1.1", "192.168.1.2"}; !reflect.DeepEqual(ips, want) { + t.Errorf("/30 = %v, want %v", ips, want) + } + + ips, err = hostIPs("10.0.0.0/24") + if err != nil { + t.Fatal(err) + } + if len(ips) != 254 || ips[0] != "10.0.0.1" || ips[253] != "10.0.0.254" { + t.Errorf("/24 = %d hosts (%q..%q), want 254 (.1...254)", len(ips), ips[0], ips[len(ips)-1]) + } +} + +func TestHostIPsRejects(t *testing.T) { + if _, err := hostIPs("10.0.0.0/8"); err == nil { + t.Error("oversized subnet should error") + } + if _, err := hostIPs("not-a-cidr"); err == nil { + t.Error("bad cidr should error") + } +} |
