Skip to content

Commit

Permalink
chore: add a testing valuer which always returns an error (#724)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjeffcaii authored Jul 28, 2023
1 parent a6636b7 commit 69019ed
Show file tree
Hide file tree
Showing 20 changed files with 83 additions and 282 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/tekwizely/pre-commit-golang
rev: v1.0.0-beta.5
rev: v1.0.0-rc.1
hooks:
- id: my-cmd-mod
name: imports-formatter
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ require (
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v20.10.11+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/dubbogo/tools v1.0.9 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-errors/errors v1.0.1 // indirect
Expand Down
209 changes: 0 additions & 209 deletions go.sum

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pkg/config/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ func TestDataSourceClusterDiff(t *testing.T) {
}

func TestGroupsDiff(t *testing.T) {

oldGroups := Groups{
&Group{
Name: "group1",
Expand Down
4 changes: 3 additions & 1 deletion pkg/config/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

package config

import "testing"
import (
"testing"
)

func TestEventTypes(t *testing.T) {
tests := []struct {
Expand Down
17 changes: 17 additions & 0 deletions pkg/proto/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ func (f FuncValuer) Value(ctx context.Context) (Value, error) {
return f(ctx)
}

type alwaysErrorValuer struct {
err error
}

func (a alwaysErrorValuer) Value(ctx context.Context) (Value, error) {
return nil, a.err
}

type directValuer struct {
v Value
}
Expand All @@ -76,6 +84,15 @@ func (t directValuer) Value(ctx context.Context) (Value, error) {
return t.v, nil
}

// ToValuerWithError returns a Valuer which always returns an error.
// NOTICE: we don't usually use this method, it's only for testing!
func ToValuerWithError(err error) Valuer {
if err == nil {
panic("the ToValuerWithError only accept non-nil error!")
}
return alwaysErrorValuer{err: err}
}

// ToValuer wraps Value to Valuer directly.
func ToValuer(value Value) Valuer {
return directValuer{v: value}
Expand Down
18 changes: 9 additions & 9 deletions pkg/runtime/function/first_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestFuncFirstValue(t *testing.T) {
for _, v := range []tt{
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
Expand All @@ -56,7 +56,7 @@ func TestFuncFirstValue(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
Expand All @@ -72,7 +72,7 @@ func TestFuncFirstValue(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueString("07:30:00"), proto.NewValueString("st113"), proto.NewValueFloat64(25)},
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
Expand All @@ -88,7 +88,7 @@ func TestFuncFirstValue(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueString("07:45:00"), proto.NewValueString("st113"), proto.NewValueFloat64(0)},
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
Expand All @@ -104,7 +104,7 @@ func TestFuncFirstValue(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueString("07:00:00"), proto.NewValueString("xh458"), proto.NewValueFloat64(0)},
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
Expand All @@ -120,7 +120,7 @@ func TestFuncFirstValue(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueString("07:15:00"), proto.NewValueString("xh458"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
Expand All @@ -136,7 +136,7 @@ func TestFuncFirstValue(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueString("07:30:00"), proto.NewValueString("xh458"), proto.NewValueFloat64(5)},
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
Expand All @@ -152,7 +152,7 @@ func TestFuncFirstValue(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueString("07:45:00"), proto.NewValueString("xh458"), proto.NewValueFloat64(30)},
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
Expand All @@ -168,7 +168,7 @@ func TestFuncFirstValue(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueString("08:00:00"), proto.NewValueString("xh458"), proto.NewValueFloat64(25)},
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
Expand Down
14 changes: 7 additions & 7 deletions pkg/runtime/function/lag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestFuncLag(t *testing.T) {
for _, v := range []tt{
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueInt64(1)},
{proto.NewValueString("12:00:00"), proto.NewValueString(""), proto.NewValueFloat64(100)},
{proto.NewValueString("12:00:00"), proto.NewValueString(""), proto.NewValueFloat64(100)},
Expand All @@ -55,7 +55,7 @@ func TestFuncLag(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueInt64(1)},
{proto.NewValueString("13:00:00"), proto.NewValueString(""), proto.NewValueFloat64(125)},
{proto.NewValueString("12:00:00"), proto.NewValueString(""), proto.NewValueFloat64(100)},
Expand All @@ -70,7 +70,7 @@ func TestFuncLag(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueInt64(1)},
{proto.NewValueString("14:00:00"), proto.NewValueString(""), proto.NewValueFloat64(132)},
{proto.NewValueString("12:00:00"), proto.NewValueString(""), proto.NewValueFloat64(100)},
Expand All @@ -85,7 +85,7 @@ func TestFuncLag(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueInt64(1)},
{proto.NewValueString("15:00:00"), proto.NewValueString(""), proto.NewValueFloat64(145)},
{proto.NewValueString("12:00:00"), proto.NewValueString(""), proto.NewValueFloat64(100)},
Expand All @@ -100,7 +100,7 @@ func TestFuncLag(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueInt64(1)},
{proto.NewValueString("16:00:00"), proto.NewValueString(""), proto.NewValueFloat64(140)},
{proto.NewValueString("12:00:00"), proto.NewValueString(""), proto.NewValueFloat64(100)},
Expand All @@ -115,7 +115,7 @@ func TestFuncLag(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueInt64(1)},
{proto.NewValueString("17:00:00"), proto.NewValueString(""), proto.NewValueFloat64(150)},
{proto.NewValueString("12:00:00"), proto.NewValueString(""), proto.NewValueFloat64(100)},
Expand All @@ -130,7 +130,7 @@ func TestFuncLag(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueInt64(1)},
{proto.NewValueString("18:00:00"), proto.NewValueString(""), proto.NewValueFloat64(200)},
{proto.NewValueString("12:00:00"), proto.NewValueString(""), proto.NewValueFloat64(100)},
Expand Down
18 changes: 9 additions & 9 deletions pkg/runtime/function/last_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestFuncLastValue(t *testing.T) {
for _, v := range []tt{
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
Expand All @@ -56,7 +56,7 @@ func TestFuncLastValue(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
Expand All @@ -72,7 +72,7 @@ func TestFuncLastValue(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueString("07:30:00"), proto.NewValueString("st113"), proto.NewValueFloat64(25)},
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
Expand All @@ -88,7 +88,7 @@ func TestFuncLastValue(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueString("07:45:00"), proto.NewValueString("st113"), proto.NewValueFloat64(0)},
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
Expand All @@ -104,7 +104,7 @@ func TestFuncLastValue(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueString("07:00:00"), proto.NewValueString("xh458"), proto.NewValueFloat64(0)},
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
Expand All @@ -120,7 +120,7 @@ func TestFuncLastValue(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueString("07:15:00"), proto.NewValueString("xh458"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
Expand All @@ -136,7 +136,7 @@ func TestFuncLastValue(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueString("07:30:00"), proto.NewValueString("xh458"), proto.NewValueFloat64(5)},
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
Expand All @@ -152,7 +152,7 @@ func TestFuncLastValue(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueString("07:45:00"), proto.NewValueString("xh458"), proto.NewValueFloat64(30)},
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
Expand All @@ -168,7 +168,7 @@ func TestFuncLastValue(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueString("08:00:00"), proto.NewValueString("xh458"), proto.NewValueFloat64(25)},
{proto.NewValueString("07:00:00"), proto.NewValueString("st113"), proto.NewValueFloat64(10)},
{proto.NewValueString("07:15:00"), proto.NewValueString("st113"), proto.NewValueFloat64(9)},
Expand Down
14 changes: 7 additions & 7 deletions pkg/runtime/function/lead_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestFuncLead(t *testing.T) {
for _, v := range []tt{
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueInt64(1)},
{proto.NewValueString("12:00:00"), proto.NewValueString(""), proto.NewValueFloat64(100)},
{proto.NewValueString("12:00:00"), proto.NewValueString(""), proto.NewValueFloat64(100)},
Expand All @@ -55,7 +55,7 @@ func TestFuncLead(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueInt64(1)},
{proto.NewValueString("13:00:00"), proto.NewValueString(""), proto.NewValueFloat64(125)},
{proto.NewValueString("12:00:00"), proto.NewValueString(""), proto.NewValueFloat64(100)},
Expand All @@ -70,7 +70,7 @@ func TestFuncLead(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueInt64(1)},
{proto.NewValueString("14:00:00"), proto.NewValueString(""), proto.NewValueFloat64(132)},
{proto.NewValueString("12:00:00"), proto.NewValueString(""), proto.NewValueFloat64(100)},
Expand All @@ -85,7 +85,7 @@ func TestFuncLead(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueInt64(1)},
{proto.NewValueString("15:00:00"), proto.NewValueString(""), proto.NewValueFloat64(145)},
{proto.NewValueString("12:00:00"), proto.NewValueString(""), proto.NewValueFloat64(100)},
Expand All @@ -100,7 +100,7 @@ func TestFuncLead(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueInt64(1)},
{proto.NewValueString("16:00:00"), proto.NewValueString(""), proto.NewValueFloat64(140)},
{proto.NewValueString("12:00:00"), proto.NewValueString(""), proto.NewValueFloat64(100)},
Expand All @@ -115,7 +115,7 @@ func TestFuncLead(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueInt64(1)},
{proto.NewValueString("17:00:00"), proto.NewValueString(""), proto.NewValueFloat64(150)},
{proto.NewValueString("12:00:00"), proto.NewValueString(""), proto.NewValueFloat64(100)},
Expand All @@ -130,7 +130,7 @@ func TestFuncLead(t *testing.T) {
},
{
[][]proto.Value{
//order column, partition column, value column
// order column, partition column, value column
{proto.NewValueInt64(1)},
{proto.NewValueString("18:00:00"), proto.NewValueString(""), proto.NewValueFloat64(200)},
{proto.NewValueString("12:00:00"), proto.NewValueString(""), proto.NewValueFloat64(100)},
Expand Down
Loading

0 comments on commit 69019ed

Please sign in to comment.