Skip to content

Commit

Permalink
feat(test): add unit test for concat_ws function
Browse files Browse the repository at this point in the history
  • Loading branch information
dongzl committed Jul 28, 2023
1 parent a6636b7 commit c8b578c
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
5 changes: 3 additions & 2 deletions pkg/runtime/function/concat_ws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import (
)

func TestConcatWSFunc_Apply(t *testing.T) {
f := proto.MustGetFunc(FuncConcatWS)
fn := proto.MustGetFunc(FuncConcatWS)
assert.Equal(t, 2, fn.NumInput())

tests := []struct {
inputs []proto.Value
Expand Down Expand Up @@ -87,7 +88,7 @@ func TestConcatWSFunc_Apply(t *testing.T) {
for i := range next.inputs {
inputs = append(inputs, proto.ToValuer(next.inputs[i]))
}
out, err := f.Apply(context.Background(), inputs...)
out, err := fn.Apply(context.Background(), inputs...)
assert.NoError(t, err)

var actual string
Expand Down
37 changes: 37 additions & 0 deletions pkg/runtime/function/cume_dist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (

func TestFuncCumeDist(t *testing.T) {
fn := proto.MustGetFunc(FuncCumeDist)
assert.Equal(t, 0, fn.NumInput())

type tt struct {
inputs []proto.Value
want string
Expand Down Expand Up @@ -125,3 +127,38 @@ func TestFuncCumeDist(t *testing.T) {
})
}
}

func TestFuncCumeDist_Error(t *testing.T) {
fn := proto.MustGetFunc(FuncCumeDist)
assert.Equal(t, 0, fn.NumInput())

type tt struct {
name string
inputs []proto.Value
}
for _, v := range []tt{
{
"Test_Nil",
[]proto.Value{
nil,
},
},
{
"Test_Nil_1",
[]proto.Value{
proto.NewValueFloat64(5),
nil,
},
},
} {
t.Run(v.name, func(t *testing.T) {
var inputs []proto.Valuer
for i := range v.inputs {
inputs = append(inputs, proto.ToValuer(v.inputs[i]))
}
out, err := fn.Apply(context.Background(), inputs...)
assert.Nil(t, err)
assert.Nil(t, out)
})
}
}
39 changes: 38 additions & 1 deletion pkg/runtime/function/dense_rank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ import (
"github.com/arana-db/arana/pkg/proto"
)

func TestFuncDenseRankt(t *testing.T) {
func TestFuncDenseRank(t *testing.T) {
fn := proto.MustGetFunc(FuncDenseRank)
assert.Equal(t, 0, fn.NumInput())

type tt struct {
inputs []proto.Value
want string
Expand Down Expand Up @@ -125,3 +127,38 @@ func TestFuncDenseRankt(t *testing.T) {
})
}
}

func TestFuncDenseRank_Error(t *testing.T) {
fn := proto.MustGetFunc(FuncDenseRank)
assert.Equal(t, 0, fn.NumInput())

type tt struct {
name string
inputs []proto.Value
}
for _, v := range []tt{
{
"Test_Nil",
[]proto.Value{
nil,
},
},
{
"Test_Nil_1",
[]proto.Value{
proto.NewValueFloat64(5),
nil,
},
},
} {
t.Run(v.name, func(t *testing.T) {
var inputs []proto.Valuer
for i := range v.inputs {
inputs = append(inputs, proto.ToValuer(v.inputs[i]))
}
out, err := fn.Apply(context.Background(), inputs...)
assert.Nil(t, err)
assert.Nil(t, out)
})
}
}

0 comments on commit c8b578c

Please sign in to comment.