Skip to content

Commit

Permalink
add ut
Browse files Browse the repository at this point in the history
  • Loading branch information
ck89119 committed Dec 17, 2024
1 parent 4cadd29 commit d0b1503
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
10 changes: 10 additions & 0 deletions pkg/frontend/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,16 @@ func TestSession_TxnCompilerContext(t *testing.T) {
convey.So(object, convey.ShouldNotBeNil)
convey.So(tableRef, convey.ShouldNotBeNil)

ref := &plan.ObjectRef{
SchemaName: "schema",
PubInfo: &plan.PubInfo{
TenantId: 0,
},
}
object, tableRef = tcc.ResolveIndexTableByRef(ref, "indexTable", &plan2.Snapshot{TS: ts})
convey.So(object, convey.ShouldNotBeNil)
convey.So(tableRef, convey.ShouldNotBeNil)

pkd := tcc.GetPrimaryKeyDef("abc", "t1", &plan2.Snapshot{TS: ts})
convey.So(len(pkd), convey.ShouldBeZeroValue)

Expand Down
8 changes: 8 additions & 0 deletions pkg/sql/plan/types_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/sql/plan/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2721,10 +2721,10 @@ func offsetToString(offset int) string {
// return !strings.HasPrefix(tableDef.Name, catalog.IndexTableNamePrefix)
// }

// DbNameOfObjRef return subscription name of ObjectRef if exists,
// DbNameOfObjRef return subscription name of ObjectRef if exists, to avoid the mismatching of account id and db name
func DbNameOfObjRef(objRef *ObjectRef) string {
if objRef.SubscriptionName == "" {
return objRef.SchemaName
}
return objRef.SubscriptionName
}
}
36 changes: 36 additions & 0 deletions pkg/sql/plan/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,39 @@ func TestHandleOptimizerHints(t *testing.T) {
handleOptimizerHints("skipDedup=1", builder)
require.Equal(t, 1, builder.optimizerHints.skipDedup)
}

func TestDbNameOfObjRef(t *testing.T) {
type args struct {
objRef *ObjectRef
}
tests := []struct {
name string
args args
want string
}{
{
name: "case 1",
args: args{
objRef: &ObjectRef{
SchemaName: "db",
},
},
want: "db",
},
{
name: "case 2",
args: args{
objRef: &ObjectRef{
SchemaName: "whatever",
SubscriptionName: "sub",
},
},
want: "sub",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, DbNameOfObjRef(tt.args.objRef), "DbNameOfObjRef(%v)", tt.args.objRef)
})
}
}

0 comments on commit d0b1503

Please sign in to comment.