open-nomad/client/fingerprint/network_test.go

53 lines
1.2 KiB
Go
Raw Normal View History

package fingerprint
import (
2015-09-23 03:56:31 +00:00
"net"
"testing"
"github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/nomad/structs"
)
func TestNetworkFingerprint_basic(t *testing.T) {
f := NewNetworkFingerprinter(testLogger())
node := &structs.Node{
Attributes: make(map[string]string),
}
2015-10-03 00:32:11 +00:00
cfg := &config.Config{NetworkSpeed: 100}
2015-10-03 00:32:11 +00:00
ok, err := f.Fingerprint(cfg, node)
if err != nil {
t.Fatalf("err: %v", err)
}
if !ok {
t.Fatalf("should apply")
}
2015-09-23 03:56:31 +00:00
assertNodeAttributeContains(t, node, "network.ip-address")
ip := node.Attributes["network.ip-address"]
match := net.ParseIP(ip)
if match == nil {
t.Fatalf("Bad IP match: %s", ip)
}
2015-09-23 04:22:23 +00:00
if node.Resources == nil || len(node.Resources.Networks) == 0 {
t.Fatal("Expected to find Network Resources")
}
// Test at least the first Network Resource
net := node.Resources.Networks[0]
if net.IP == "" {
t.Fatal("Expected Network Resource to not be empty")
}
2015-09-23 04:51:56 +00:00
if net.CIDR == "" {
t.Fatal("Expected Network Resource to have a CIDR")
}
if net.Device == "" {
t.Fatal("Expected Network Resource to have a Device Name")
}
2015-10-03 00:32:11 +00:00
if net.MBits == 0 {
t.Fatal("Expected Network Resource to have a non-zero bandwith")
}
}