Skip to content

Commit

Permalink
test: add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
dongzl committed Jan 26, 2024
1 parent 35d9d72 commit 6de43de
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pkg/proto/rule/rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package rule

import (
"fmt"
"reflect"
"testing"
)

Expand Down Expand Up @@ -149,3 +150,36 @@ func TestRule(t *testing.T) {
assert.False(t, ru.Has("student"))
assert.False(t, (*Rule)(nil).Has("student"))
}

func TestGetShardColumn_Found(t *testing.T) {
sm := ShardMetadata{
ShardColumns: []*ShardColumn{
{Name: "column1"},
{Name: "column2"},
{Name: "column3"},
},
}

name := "column2"
expected := &ShardColumn{Name: "column2"}
result := sm.GetShardColumn(name)

assert.True(t, reflect.DeepEqual(result, expected))
}

func TestGetShardColumn_NotFound(t *testing.T) {
sm := ShardMetadata{
ShardColumns: []*ShardColumn{
{Name: "column1"},
{Name: "column2"},
{Name: "column3"},
},
}

name := "column4"
expected := (*ShardColumn)(nil)
result := sm.GetShardColumn(name)

assert.Nil(t, result)
assert.True(t, reflect.DeepEqual(result, expected))
}

0 comments on commit 6de43de

Please sign in to comment.