github.com/kardianos/nomad@v0.1.3-0.20151022182107-b13df73ee850/client/fingerprint/network_test.go (about)

     1  package fingerprint
     2  
     3  import (
     4  	"net"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/nomad/client/config"
     8  	"github.com/hashicorp/nomad/nomad/structs"
     9  )
    10  
    11  func TestNetworkFingerprint_basic(t *testing.T) {
    12  	f := NewNetworkFingerprinter(testLogger())
    13  	node := &structs.Node{
    14  		Attributes: make(map[string]string),
    15  	}
    16  	cfg := &config.Config{NetworkSpeed: 100}
    17  
    18  	ok, err := f.Fingerprint(cfg, node)
    19  	if err != nil {
    20  		t.Fatalf("err: %v", err)
    21  	}
    22  	if !ok {
    23  		t.Fatalf("should apply")
    24  	}
    25  
    26  	assertNodeAttributeContains(t, node, "network.ip-address")
    27  
    28  	ip := node.Attributes["network.ip-address"]
    29  	match := net.ParseIP(ip)
    30  	if match == nil {
    31  		t.Fatalf("Bad IP match: %s", ip)
    32  	}
    33  
    34  	if node.Resources == nil || len(node.Resources.Networks) == 0 {
    35  		t.Fatal("Expected to find Network Resources")
    36  	}
    37  
    38  	// Test at least the first Network Resource
    39  	net := node.Resources.Networks[0]
    40  	if net.IP == "" {
    41  		t.Fatal("Expected Network Resource to not be empty")
    42  	}
    43  	if net.CIDR == "" {
    44  		t.Fatal("Expected Network Resource to have a CIDR")
    45  	}
    46  	if net.Device == "" {
    47  		t.Fatal("Expected Network Resource to have a Device Name")
    48  	}
    49  	if net.MBits == 0 {
    50  		t.Fatal("Expected Network Resource to have a non-zero bandwith")
    51  	}
    52  }