39 lines
963 B
Go
39 lines
963 B
Go
package pciids
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
func TestExternalPCIIDsLookup(t *testing.T) {
|
|
dir := t.TempDir()
|
|
idsPath := filepath.Join(dir, "pci.ids")
|
|
content := "" +
|
|
"# sample\n" +
|
|
"10de NVIDIA Corporation\n" +
|
|
"\t233b NVIDIA H200 SXM\n" +
|
|
"8086 Intel Corporation\n" +
|
|
"\t1521 I350 Gigabit Network Connection\n"
|
|
|
|
if err := os.WriteFile(idsPath, []byte(content), 0o644); err != nil {
|
|
t.Fatalf("write pci.ids: %v", err)
|
|
}
|
|
|
|
t.Setenv("LOGPILE_PCI_IDS_PATH", idsPath)
|
|
loadOnce = sync.Once{}
|
|
vendors = nil
|
|
devices = nil
|
|
|
|
if got := DeviceName(0x10de, 0x233b); got != "NVIDIA H200 SXM" {
|
|
t.Fatalf("expected external device name, got %q", got)
|
|
}
|
|
if got := VendorName(0x10de); got != "NVIDIA Corporation" {
|
|
t.Fatalf("expected external vendor name, got %q", got)
|
|
}
|
|
if got := DeviceName(0x8086, 0x1521); got != "I350 Gigabit Network Connection" {
|
|
t.Fatalf("expected external intel device name, got %q", got)
|
|
}
|
|
}
|