devicepath/sata_test.go
Melora Hugues 54794b57a4
All checks were successful
continuous-integration/drone/push Build is passing
add beginning of parser
2023-08-27 15:09:30 +02:00

42 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`)
})
}