github.com/jaypipes/ghw@v0.21.1/pkg/pci/pci_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 pci_test
     8  
     9  import (
    10  	"os"
    11  	"testing"
    12  
    13  	"github.com/jaypipes/ghw/pkg/pci"
    14  )
    15  
    16  func TestPCI(t *testing.T) {
    17  	if _, ok := os.LookupEnv("GHW_TESTING_SKIP_PCI"); ok {
    18  		t.Skip("Skipping PCI tests.")
    19  	}
    20  
    21  	info, err := pci.New()
    22  	if err != nil {
    23  		t.Fatalf("Expected no error creating PciInfo, but got %v", err)
    24  	}
    25  
    26  	// Since we can't count on a specific device being present on the machine
    27  	// being tested (and we haven't built in fixtures/mocks for things yet)
    28  	// about all we can do is verify that the returned list of pointers to
    29  	// PCIDevice structs is non-empty
    30  	devs := info.Devices
    31  	if len(devs) == 0 {
    32  		t.Fatalf("Expected to find >0 PCI devices in PCIInfo.Devices but got 0.")
    33  	}
    34  
    35  	// Ensure that the data fields are at least populated, even if we don't yet
    36  	// check for data accuracy
    37  	for _, dev := range devs {
    38  		if dev.Class == nil {
    39  			t.Fatalf("Expected device class for %s to be non-nil", dev.Address)
    40  		}
    41  		if dev.Product == nil {
    42  			t.Fatalf("Expected device product for %s to be non-nil", dev.Address)
    43  		}
    44  		if dev.Vendor == nil {
    45  			t.Fatalf("Expected device vendor for %s to be non-nil", dev.Address)
    46  		}
    47  		if dev.Revision == "" {
    48  			t.Fatalf("Expected device revision for %s to be non-empty", dev.Address)
    49  		}
    50  		if dev.Subclass == nil {
    51  			t.Fatalf("Expected device subclass for %s to be non-nil", dev.Address)
    52  		}
    53  		if dev.Subsystem == nil {
    54  			t.Fatalf("Expected device subsystem for %s to be non-nil", dev.Address)
    55  		}
    56  		if dev.ProgrammingInterface == nil {
    57  			t.Fatalf("Expected device programming interface for %s to be non-nil", dev.Address)
    58  		}
    59  	}
    60  }