-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathoui_test.go
More file actions
54 lines (47 loc) · 1.8 KB
/
oui_test.go
File metadata and controls
54 lines (47 loc) · 1.8 KB
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
48
49
50
51
52
53
54
package mactracker
import "testing"
func TestOuiLookup(t *testing.T) {
// Test known OUI
block := LookupBytes(OuiHardwareAddr{0x00, 0x1b, 0xc5, 0x00, 0x00, 0x00})
if block == nil || block.Vendor != "Converging Systems Inc." {
t.Errorf("Expected to find Converging Systems Inc., got %v", block)
}
// The zero OUI is registered to Xerox but should not return a valid registration
block = LookupBytes(OuiHardwareAddr{0x00, 0x00, 0x00, 0x00, 0x00, 0x00})
if block != nil {
t.Errorf("Expected to find no block for unknown OUI, got %v", block)
}
// Test lookup of a private registration with an override
block = LookupBytes(OuiHardwareAddr{0xd0, 0xc9, 0x07, 0x01, 0x02, 0x03})
if block == nil || block.Vendor != "Govee" {
t.Errorf("Expected to find Govee for private OUI, got %v", block)
}
// Test lookup of a known virtual OUI
block = LookupBytes(OuiHardwareAddr{0x50, 0x54, 0x00, 0x00, 0x00, 0x00})
if block == nil || block.Vendor != "QEMU" {
t.Errorf("Expected to find QEMU for private OUI, got %v", block)
}
}
func TestLookupVirtual(t *testing.T) {
tests := []struct {
mac string
want string
}{
{mac: "50:54:00:12:34:56", want: VirtTypeQEMU},
{mac: "54:52:00:12:34:56", want: VirtTypeKVM},
{mac: "00:1c:42:12:34:56", want: VirtTypeParallels},
{mac: "2c:c2:60:12:34:56", want: VirtTypeOracle},
{mac: "08:00:27:12:34:56", want: VirtTypeVirtualBox},
{mac: "00:50:56:12:34:56", want: VirtTypeVMware},
{mac: "00:16:3E:12:34:56", want: VirtTypeXen},
{mac: "00:15:5d:12:34:56", want: VirtTypeHyperV},
{mac: "bc:24:11:12:34:56", want: VirtTypeProxmox},
{mac: "00:00:00:00:00:00", want: ""},
{mac: "invalid", want: ""},
}
for _, test := range tests {
if got := LookupVirtual(test.mac); got != test.want {
t.Errorf("LookupVirtual(%q) = %q, want %q", test.mac, got, test.want)
}
}
}