Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for internal/errors/runtime #984

Merged
merged 8 commits into from
Feb 8, 2021
Prev Previous commit
Next Next commit
✅ update runtime_test with feedback
Signed-off-by: vankichi <[email protected]>
  • Loading branch information
vankichi authored and kevindiu committed Feb 8, 2021
commit 50ea9f01c829cc697d76134fbc379c48dc362dd7
25 changes: 20 additions & 5 deletions internal/errors/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package errors

import (
"fmt"
"math"
"runtime"
"testing"
Expand Down Expand Up @@ -285,7 +284,7 @@ func TestErrPanicString(t *testing.T) {
}(),
func() test {
return test{
name: "return an error when err not nil and msg is not empty",
name: "return an error when err is nil and msg is not empty",
args: args{
msg: defaultMsg,
},
Expand All @@ -294,6 +293,15 @@ func TestErrPanicString(t *testing.T) {
},
}
}(),
vankichi marked this conversation as resolved.
Show resolved Hide resolved
func() test {
return test{
name: "return an error when err is nil and msg is empty",
args: args{},
want: want{
want: Wrap(nil, New("panic recovered: ").Error()),
},
}
}(),
}
for _, tc := range tests {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
only one cuddle assignment allowed before range statement (wsl)

test := tc
Expand All @@ -318,8 +326,6 @@ func TestErrPanicString(t *testing.T) {
}
}

type runtimeError runtime.Error

type runtimeErr struct {
err error
}
Expand Down Expand Up @@ -391,6 +397,15 @@ func TestErrRuntimeError(t *testing.T) {
},
}
}(),
vankichi marked this conversation as resolved.
Show resolved Hide resolved
func() test {
return test{
name: "return an error when err is nil and msg is nil",
args: args{},
want: want{
want: Wrap(nil, Errorf("system panicked caused by runtime error: %v", nil).Error()),
},
}
}(),
}
for _, tc := range tests {
test := tc
Expand All @@ -406,7 +421,7 @@ func TestErrRuntimeError(t *testing.T) {
if test.checkFunc == nil {
test.checkFunc = defaultCheckFunc
}
fmt.Println(test.args.r)

got := ErrRuntimeError(test.args.err, test.args.r)
if err := test.checkFunc(test.want, got); err != nil {
tt.Errorf("error = %v", err)
Expand Down