mirror of
https://github.com/bettercap/bettercap
synced 2025-07-30 11:40:33 -07:00
Note: needs refactoring to include an actual alias map example. I was unable to get this to work for the time being, but this test adds at least some coverage.
48 lines
1 KiB
Go
48 lines
1 KiB
Go
package network
|
|
|
|
import (
|
|
"net"
|
|
"testing"
|
|
)
|
|
|
|
func TestIsZeroMac(t *testing.T) {
|
|
exampleMAC, _ := net.ParseMAC("00:00:00:00:00:00")
|
|
|
|
exp := true
|
|
got := IsZeroMac(exampleMAC)
|
|
if got != exp {
|
|
t.Fatalf("expected '%t', got '%t'", exp, got)
|
|
}
|
|
}
|
|
|
|
func TestIsBroadcastMac(t *testing.T) {
|
|
exampleMAC, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
|
|
|
|
exp := true
|
|
got := IsBroadcastMac(exampleMAC)
|
|
if got != exp {
|
|
t.Fatalf("expected '%t', got '%t'", exp, got)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeMac(t *testing.T) {
|
|
exp := "ff:ff:ff:ff:ff:ff"
|
|
got := NormalizeMac("fF-fF-fF-fF-fF-fF")
|
|
if got != exp {
|
|
t.Fatalf("expected '%s', got '%s'", exp, got)
|
|
}
|
|
}
|
|
|
|
// TODO: refactor to parse targets with an actual alias map
|
|
func TestParseTargets(t *testing.T) {
|
|
ips, macs, err := ParseTargets("192.168.1.2, 192.168.1.3", &Aliases{})
|
|
if err != nil {
|
|
t.Error("ips:", ips, "macs:", macs, "err:", err)
|
|
}
|
|
if len(ips) != 2 {
|
|
t.Fatalf("expected '%d', got '%d'", 2, len(ips))
|
|
}
|
|
if len(macs) != 0 {
|
|
t.Fatalf("expected '%d', got '%d'", 0, len(macs))
|
|
}
|
|
}
|