-
Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathpci_test.go
47 lines (38 loc) · 880 Bytes
/
pci_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package decoder
import (
"bytes"
"testing"
"github.com/cloudflare/ebpf_exporter/v2/config"
)
func testPCIMissing(t *testing.T, d Decoder, cases [][]byte) {
if pci != nil {
t.Skip("PCI DB is available")
}
for _, c := range cases {
out, err := d.Decode(c, config.Decoder{})
if err != nil {
t.Errorf("Error decoding %#v: %v", c, err)
}
if !bytes.Equal(out, []byte(missingPciIDsText)) {
t.Errorf("Expected %q, got %s", missingPciIDsText, out)
}
}
}
type pciCase struct {
in []byte
out []byte
}
func testPCIPresent(t *testing.T, d Decoder, cases []pciCase) {
if pci == nil {
t.Skip("PCI DB is not available")
}
for _, c := range cases {
out, err := d.Decode(c.in, config.Decoder{})
if err != nil {
t.Errorf("Error decoding %#v: %v", c.in, err)
}
if !bytes.Equal(out, c.out) {
t.Errorf("Expected %q, got %q", c.out, out)
}
}
}