summaryrefslogtreecommitdiff
path: root/adapters/netscan/netscan_test.go
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2026-06-20 09:40:07 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2026-06-20 09:40:07 -0700
commitfb653292612eddca5b088ed88466c546d1597107 (patch)
tree900ed32e066812688858ed3bb15128c41bb78054 /adapters/netscan/netscan_test.go
downloadpenguins.lan-fb653292612eddca5b088ed88466c546d1597107.tar.gz
penguins.lan-fb653292612eddca5b088ed88466c546d1597107.zip
Initial commit
Diffstat (limited to 'adapters/netscan/netscan_test.go')
-rw-r--r--adapters/netscan/netscan_test.go33
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")
+ }
+}