devicepath/sata_test.go

43 lines
1.4 KiB
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"
"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`)
})
}