Skip to content

Commit

Permalink
keyspace: fix keyspace ut (#41375)
Browse files Browse the repository at this point in the history
close #41376
  • Loading branch information
ystaticy committed Feb 14, 2023
1 parent 74875da commit 3b445df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
2 changes: 1 addition & 1 deletion keyspace/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ go_test(
flaky = True,
deps = [
"//config",
"@com_github_stretchr_testify//suite",
"@com_github_stretchr_testify//require",
],
)
35 changes: 14 additions & 21 deletions keyspace/keyspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,14 @@ import (
"testing"

"github.com/pingcap/tidb/config"
"github.com/stretchr/testify/suite"
"github.com/stretchr/testify/require"
)

type keyspaceSuite struct {
suite.Suite
}

func TestSetKeyspaceName(t *testing.T) {
suite.Run(t, new(keyspaceSuite))
}
func TestSetKeyspaceNameInConf(t *testing.T) {
config.UpdateGlobal(func(conf *config.Config) {
conf.KeyspaceName = ""
})

func (k *keyspaceSuite) TearDownTest() {
// Clear keyspace setting
conf := config.GetGlobalConfig()
conf.KeyspaceName = ""
config.StoreGlobalConfig(conf)
}

func (k *keyspaceSuite) TestSetKeyspaceNameInConf() {
keyspaceNameInCfg := "test_keyspace_cfg"

// Set KeyspaceName in conf
Expand All @@ -47,13 +36,17 @@ func (k *keyspaceSuite) TestSetKeyspaceNameInConf() {

// Check the keyspaceName which get from GetKeyspaceNameBySettings, equals keyspaceNameInCfg which is in conf.
// The cfg.keyspaceName get higher weights than KEYSPACE_NAME in system env.
k.Equal(keyspaceNameInCfg, getKeyspaceName)
k.Equal(false, IsKeyspaceNameEmpty(getKeyspaceName))
require.Equal(t, keyspaceNameInCfg, getKeyspaceName)
require.Equal(t, false, IsKeyspaceNameEmpty(getKeyspaceName))
}

func (k *keyspaceSuite) TestNoKeyspaceNameSet() {
func TestNoKeyspaceNameSet(t *testing.T) {
config.UpdateGlobal(func(conf *config.Config) {
conf.KeyspaceName = ""
})

getKeyspaceName := GetKeyspaceNameBySettings()

k.Equal("", getKeyspaceName)
k.Equal(true, IsKeyspaceNameEmpty(getKeyspaceName))
require.Equal(t, "", getKeyspaceName)
require.Equal(t, true, IsKeyspaceNameEmpty(getKeyspaceName))
}

0 comments on commit 3b445df

Please sign in to comment.