43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
|
package devicepath_test
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
devicepath "git.faercol.me/faercol/device-path"
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
"github.com/stretchr/testify/require"
|
||
|
)
|
||
|
|
||
|
func TestParseString(t *testing.T) {
|
||
|
t.Run("OK", func(t *testing.T) {
|
||
|
var sataDev devicepath.SataDevicePath
|
||
|
require.NoError(t, sataDev.ParseString("Sata(1,65535,0)"))
|
||
|
assert.Equal(t, "Sata(1,65535,0)", sataDev.String())
|
||
|
})
|
||
|
|
||
|
t.Run("Err invalid prefix", func(t *testing.T) {
|
||
|
var sataDev devicepath.SataDevicePath
|
||
|
assert.ErrorIs(t, sataDev.ParseString("PciRoot(0x0)"), devicepath.ErrMalformedString)
|
||
|
})
|
||
|
|
||
|
t.Run("Err invalid number arguments", func(t *testing.T) {
|
||
|
var sataDev devicepath.SataDevicePath
|
||
|
assert.ErrorContains(t, sataDev.ParseString("Sata(1,2,3,4)"), "unexpected number of arguments")
|
||
|
})
|
||
|
|
||
|
t.Run("Err invalid format arg0", func(t *testing.T) {
|
||
|
var sataDev devicepath.SataDevicePath
|
||
|
assert.ErrorContains(t, sataDev.ParseString("Sata(toto,65535,0)"), `strconv.Atoi: parsing "toto": invalid syntax`)
|
||
|
})
|
||
|
|
||
|
t.Run("Err invalid format arg1", func(t *testing.T) {
|
||
|
var sataDev devicepath.SataDevicePath
|
||
|
assert.ErrorContains(t, sataDev.ParseString("Sata(0,toto,0)"), `strconv.Atoi: parsing "toto": invalid syntax`)
|
||
|
})
|
||
|
|
||
|
t.Run("Err invalid format arg2", func(t *testing.T) {
|
||
|
var sataDev devicepath.SataDevicePath
|
||
|
assert.ErrorContains(t, sataDev.ParseString("Sata(0,65535,toto)"), `strconv.Atoi: parsing "toto": invalid syntax`)
|
||
|
})
|
||
|
}
|