http-boot-config/config/efivar/efivar_test.go

33 lines
822 B
Go
Raw Permalink Normal View History

2023-08-22 20:39:23 +00:00
package efivar
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNumSliceToBytes(t *testing.T) {
t.Run("OK", func(t *testing.T) {
expected := []byte{12, 53, 124, 84}
input := []string{"12", "53", "124", "84"}
res, err := numSliceToBytes(input)
require.NoError(t, err)
assert.Equal(t, expected, res)
})
t.Run("Err - invalid byte", func(t *testing.T) {
input := []string{"12", "11453", "124"}
res, err := numSliceToBytes(input)
require.ErrorContains(t, err, "value 11453 at index 1 out of range")
assert.Nil(t, res)
})
t.Run("Err - not numbers", func(t *testing.T) {
input := []string{"12", "toto", "124"}
res, err := numSliceToBytes(input)
require.ErrorContains(t, err, "invalid number toto at index 1")
assert.Nil(t, res)
})
}