devicepath/pci_test.go

40 lines
960 B
Go
Raw Permalink Normal View History

2023-08-27 13:09:30 +00:00
package devicepath_test
import (
"testing"
2023-09-16 14:20:09 +00:00
"git.faercol.me/faercol/devicepath"
2023-08-27 13:09:30 +00:00
"github.com/stretchr/testify/assert"
2023-09-18 11:55:47 +00:00
"github.com/stretchr/testify/require"
2023-08-27 13:09:30 +00:00
)
func TestToString(t *testing.T) {
t.Run("Only digits", func(t *testing.T) {
expected := "Pci(0x0,0x1)"
dev := devicepath.NewPCIDevicePath(0, 1)
assert.Equal(t, expected, dev.String())
})
t.Run("Letters", func(t *testing.T) {
expected := "Pci(0x2,0xa)"
dev := devicepath.NewPCIDevicePath(2, 10)
assert.Equal(t, expected, dev.String())
})
}
2023-09-18 11:55:47 +00:00
func TestParsePCIString(t *testing.T) {
t.Run("OK device < 16", func(t *testing.T) {
rawStr := "Pci(0x0,0x1)"
var dev devicepath.PCIDevicePath
require.NoError(t, dev.ParseString(rawStr))
assert.Equal(t, rawStr, dev.String())
})
t.Run("OK device > 16", func(t *testing.T) {
rawStr := "Pci(0x1f,0x2)"
var dev devicepath.PCIDevicePath
require.NoError(t, dev.ParseString(rawStr))
assert.Equal(t, rawStr, dev.String())
})
}