github.com/jaypipes/ghw@v0.21.1/pkg/net/net_test.go (about)

     1  //
     2  // Use and distribution licensed under the Apache license version 2.
     3  //
     4  // See the COPYING file in the root project directory for full text.
     5  //
     6  
     7  package net_test
     8  
     9  import (
    10  	"os"
    11  	"testing"
    12  
    13  	"github.com/jaypipes/ghw/pkg/net"
    14  )
    15  
    16  func TestNet(t *testing.T) {
    17  	if _, ok := os.LookupEnv("GHW_TESTING_SKIP_NET"); ok {
    18  		t.Skip("Skipping network tests.")
    19  	}
    20  
    21  	info, err := net.New()
    22  
    23  	if err != nil {
    24  		t.Fatalf("Expected nil err, but got %v", err)
    25  	}
    26  	if info == nil {
    27  		t.Fatalf("Expected non-nil NetworkInfo, but got nil")
    28  	}
    29  
    30  	if len(info.NICs) > 0 {
    31  		for _, n := range info.NICs {
    32  			if n.Name == "" {
    33  				t.Fatalf("Expected a NIC name but got \"\".")
    34  			}
    35  		}
    36  	}
    37  }