Skip to content

Commit

Permalink
test(embedded/sql): uuid data-type coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Jeronimo Irazabal <[email protected]>
  • Loading branch information
jeroiraz committed Oct 10, 2023
1 parent 04a7c4c commit 114ea99
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions embedded/sql/stmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"testing"
"time"

"github.com/google/uuid"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -222,6 +223,22 @@ func TestRequiresTypeNumExpValueExp(t *testing.T) {
requiredType: Float64Type,
expectedError: ErrInvalidTypes,
},
{
exp: &UUID{val: uuid.New()},
cols: cols,
params: params,
implicitTable: "mytable",
requiredType: UUIDType,
expectedError: nil,
},
{
exp: &UUID{val: uuid.New()},
cols: cols,
params: params,
implicitTable: "mytable",
requiredType: Float64Type,
expectedError: ErrInvalidTypes,
},
}

for i, tc := range testCases {
Expand Down Expand Up @@ -686,6 +703,7 @@ func TestIsConstant(t *testing.T) {
require.True(t, (&Varchar{}).isConstant())
require.True(t, (&Bool{}).isConstant())
require.True(t, (&Blob{}).isConstant())
require.True(t, (&UUID{}).isConstant())
require.True(t, (&Timestamp{}).isConstant())
require.True(t, (&Param{}).isConstant())
require.False(t, (&ColSelector{}).isConstant())
Expand Down Expand Up @@ -962,3 +980,54 @@ func TestFloat64Type(t *testing.T) {
err = ts.selectorRanges(&Table{}, "", map[string]interface{}{}, map[uint32]*typedValueRange{})
require.NoError(t, err)
}

func TestUUIDType(t *testing.T) {

id := &UUID{val: uuid.New()}

t.Run("comparison functions", func(t *testing.T) {
cmp, err := id.Compare(&UUID{val: id.val})
require.NoError(t, err)
require.Equal(t, 0, cmp)

cmp, err = id.Compare(&UUID{val: uuid.New()})
require.NoError(t, err)
require.NotZero(t, cmp)

cmp, err = id.Compare(&NullValue{t: UUIDType})
require.NoError(t, err)
require.Equal(t, 1, cmp)

cmp, err = id.Compare(&NullValue{t: AnyType})
require.NoError(t, err)
require.Equal(t, 1, cmp)

_, err = id.Compare(&Float64{})
require.ErrorIs(t, err, ErrNotComparableValues)
})

err := id.requiresType(UUIDType, map[string]ColDescriptor{}, map[string]string{}, "")
require.NoError(t, err)

err = id.requiresType(IntegerType, map[string]ColDescriptor{}, map[string]string{}, "")
require.ErrorIs(t, err, ErrInvalidTypes)

v, err := id.substitute(map[string]interface{}{})
require.NoError(t, err)
require.Equal(t, id, v)

v = id.reduceSelectors(&Row{}, "")
require.Equal(t, id, v)

err = id.selectorRanges(&Table{}, "", map[string]interface{}{}, map[uint32]*typedValueRange{})
require.NoError(t, err)

err = (&NullValue{}).selectorRanges(&Table{}, "", map[string]interface{}{}, map[uint32]*typedValueRange{})
require.NoError(t, err)

err = (&Integer{}).selectorRanges(&Table{}, "", map[string]interface{}{}, map[uint32]*typedValueRange{})
require.NoError(t, err)

err = (&Varchar{}).selectorRanges(&Table{}, "", map[string]interface{}{}, map[uint32]*typedValueRange{})
require.NoError(t, err)
}

0 comments on commit 114ea99

Please sign in to comment.