add test for EachHost

This commit is contained in:
Kent Gruber 2018-05-01 15:02:30 -04:00
parent 050eaaf6bc
commit 4b82e917c7

View file

@ -143,3 +143,19 @@ func TestHas(t *testing.T) {
t.Error("unable find a known IP address in LAN struct")
}
}
func TestEachHost(t *testing.T) {
exampleBuffer := []string{}
exampleLAN := buildExampleLAN()
exampleEndpoint := buildExampleEndpoint()
exampleLAN.hosts[exampleEndpoint.HwAddress] = exampleEndpoint
exampleCB := func(mac string, e *Endpoint) {
exampleBuffer = append(exampleBuffer, exampleEndpoint.HwAddress)
}
exampleLAN.EachHost(exampleCB)
exp := 1
got := len(exampleBuffer)
if got != exp {
t.Fatalf("expected '%d', got '%d'", exp, got)
}
}