Newer
Older
"github.com/stretchr/testify/require"
)
type ToBoolTestCase struct {
Input string
ExpectError bool // if you expect an error put true here
}
func TestToBool(t *testing.T) {
tCases := []ToBoolTestCase{
{
Input: "1",
ExpectError: false,
},
{
Input: "0",
ExpectError: false,
},
{
Input: "True",
ExpectError: false,
},
{
Input: "true",
ExpectError: false,
},
{
Input: "False",
ExpectError: false,
},
{
Input: "false",
ExpectError: false,
},
{
Input: "flase",
ExpectError: true,
},
}
for _, tCase := range tCases {
res, err := toBool(tCase.Input)
if tCase.ExpectError {
require.Error(t, err)
} else {
require.NoError(t, err)
require.Equal(t, tCase.Output, res)