Skip to content

Commit 0284186

Browse files
committed
adding data-driven tests
1 parent 5a4797a commit 0284186

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

shared/database/database_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import (
44
"testing"
55

66
"github.com/xmlking/micro-starter-kit/shared/config"
7+
8+
_ "github.com/jinzhu/gorm/dialects/sqlite"
9+
_ "github.com/xmlking/micro-starter-kit/shared/log"
710
)
811

912
func TestDatabase(t *testing.T) {

shared/errors/errors.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var appErrors = map[ErrorCode]ErrorDetail{
3636
}
3737

3838
// AppError - App specific Error
39-
func AppError(errorCode ErrorCode, a ...interface{}) error {
39+
func AppError(errorCode ErrorCode, a ...interface{}) *errors.Error {
4040
return &errors.Error{
4141
Id: appErrors[errorCode].ID,
4242
Code: appErrors[errorCode].Code,
@@ -46,7 +46,7 @@ func AppError(errorCode ErrorCode, a ...interface{}) error {
4646
}
4747

4848
// ValidationError - Unprocessable Entity
49-
func ValidationError(id, format string, a ...interface{}) error {
49+
func ValidationError(id, format string, a ...interface{}) *errors.Error {
5050
return &errors.Error{
5151
Id: id,
5252
Code: 422,

shared/errors/errors_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
package errors
22

3+
// TODO: https://gochronicles.dev/posts/datastructures/list/singlylinkedlist/part-ii/
4+
35
import (
46
errs "errors"
57
"net/http"
8+
"reflect"
69
"testing"
710

811
"github.com/micro/go-micro/errors"
912
)
1013

1114
func TestErrors(t *testing.T) {
15+
testCases := []struct {
16+
name string
17+
values string
18+
want *errors.Error
19+
}{
20+
{"EC1", "not good", AppError(EC1)},
21+
}
22+
1223
testData := []*errors.Error{
1324
&errors.Error{
1425
Id: "go.micro.srv.account",
@@ -27,6 +38,16 @@ func TestErrors(t *testing.T) {
2738
},
2839
}
2940

41+
// test AppError
42+
for _, tc := range testCases {
43+
t.Run(tc.name, func(t *testing.T) {
44+
got := AppError(EC1)
45+
if !reflect.DeepEqual(got, tc.want) {
46+
t.Errorf("Got %v, want %v", got, tc.want)
47+
}
48+
})
49+
}
50+
3051
// test ValidationError
3152
for _, e := range testData {
3253
ne := ValidationError("go.micro.srv.account", "proto validation: sumo-val-error")

0 commit comments

Comments
 (0)