Skip to content

Commit

Permalink
✅ ♻️ add test
Browse files Browse the repository at this point in the history
Signed-off-by: vankichi <[email protected]>
  • Loading branch information
vankichi committed Feb 15, 2021
1 parent f0e1191 commit 2550884
Showing 1 changed file with 60 additions and 23 deletions.
83 changes: 60 additions & 23 deletions internal/db/rdb/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2068,8 +2068,8 @@ func Test_mySQLClient_SetVector(t *testing.T) {

func Test_mySQLClient_SetVectors(t *testing.T) {
type args struct {
ctx context.Context
datas []Vector
ctx context.Context
data []Vector
}
type fields struct {
session dbr.Session
Expand Down Expand Up @@ -2100,8 +2100,8 @@ func Test_mySQLClient_SetVectors(t *testing.T) {
return test{
name: "return error when mysql connection is closed",
args: args{
ctx: context.Background(),
datas: m,
ctx: context.Background(),
data: m,
},
fields: fields{
connected: func() (v atomic.Value) {
Expand All @@ -2114,14 +2114,33 @@ func Test_mySQLClient_SetVectors(t *testing.T) {
},
}
}(),
func() test {
var m []Vector
return test{
name: "return error when mysql session is nil",
args: args{
ctx: context.Background(),
data: m,
},
fields: fields{
connected: func() (v atomic.Value) {
v.Store(true)
return
}(),
},
want: want{
err: errors.ErrMySQLSessionNil,
},
}
}(),
func() test {
var m []Vector
err := errors.New("session.Begin error")
return test{
name: "return error when session.Begin fails",
args: args{
ctx: context.Background(),
datas: m,
ctx: context.Background(),
data: m,
},
fields: fields{
session: &dbr.MockSession{
Expand All @@ -2145,8 +2164,8 @@ func Test_mySQLClient_SetVectors(t *testing.T) {
return test{
name: "return error when data vector is invalid",
args: args{
ctx: context.Background(),
datas: m,
ctx: context.Background(),
data: m,
},
fields: fields{
session: &dbr.MockSession{
Expand Down Expand Up @@ -2178,8 +2197,8 @@ func Test_mySQLClient_SetVectors(t *testing.T) {
return test{
name: "return error when insertbysql ExecContext returns error",
args: args{
ctx: context.Background(),
datas: m,
ctx: context.Background(),
data: m,
},
fields: fields{
session: &dbr.MockSession{
Expand Down Expand Up @@ -2218,8 +2237,8 @@ func Test_mySQLClient_SetVectors(t *testing.T) {
return test{
name: "return error when select loadcontext returns error",
args: args{
ctx: context.Background(),
datas: m,
ctx: context.Background(),
data: m,
},
fields: fields{
session: &dbr.MockSession{
Expand Down Expand Up @@ -2278,8 +2297,8 @@ func Test_mySQLClient_SetVectors(t *testing.T) {
return test{
name: "return error when elem not found by uuid",
args: args{
ctx: context.Background(),
datas: m,
ctx: context.Background(),
data: m,
},
fields: fields{
session: &dbr.MockSession{
Expand Down Expand Up @@ -2352,8 +2371,8 @@ func Test_mySQLClient_SetVectors(t *testing.T) {
return test{
name: "return error when delete ExecContext returns error",
args: args{
ctx: context.Background(),
datas: m,
ctx: context.Background(),
data: m,
},
fields: fields{
session: &dbr.MockSession{
Expand Down Expand Up @@ -2436,8 +2455,8 @@ func Test_mySQLClient_SetVectors(t *testing.T) {
return test{
name: "return error when insert ExecContext returns error",
args: args{
ctx: context.Background(),
datas: m,
ctx: context.Background(),
data: m,
},
fields: fields{
session: &dbr.MockSession{
Expand Down Expand Up @@ -2533,8 +2552,8 @@ func Test_mySQLClient_SetVectors(t *testing.T) {
return test{
name: "return error when tx.Commit returns error",
args: args{
ctx: context.Background(),
datas: m,
ctx: context.Background(),
data: m,
},
fields: fields{
session: &dbr.MockSession{
Expand Down Expand Up @@ -2632,8 +2651,8 @@ func Test_mySQLClient_SetVectors(t *testing.T) {
return test{
name: "return nil when setVector ends with success",
args: args{
ctx: context.Background(),
datas: m,
ctx: context.Background(),
data: m,
},
fields: fields{
session: &dbr.MockSession{
Expand Down Expand Up @@ -2735,7 +2754,7 @@ func Test_mySQLClient_SetVectors(t *testing.T) {
dbr: test.fields.dbr,
}

err := m.SetVectors(test.args.ctx, test.args.datas...)
err := m.SetVectors(test.args.ctx, test.args.data...)
if err := test.checkFunc(test.want, err); err != nil {
tt.Errorf("error = %v", err)
}
Expand Down Expand Up @@ -2791,6 +2810,24 @@ func Test_mySQLClient_deleteVector(t *testing.T) {
},
}
}(),
func() test {
return test{
name: "return error when MySQL session is nil",
args: args{
ctx: context.Background(),
val: "vald-01",
},
fields: fields{
connected: func() (v atomic.Value) {
v.Store(true)
return
}(),
},
want: want{
err: errors.ErrMySQLSessionNil,
},
}
}(),
func() test {
err := errors.New("Begin error")
return test{
Expand Down

0 comments on commit 2550884

Please sign in to comment.