Skip to content

Commit

Permalink
[parser] parser: move policyinfo test from tidb to parser (pingcap#1330)
Browse files Browse the repository at this point in the history
  • Loading branch information
AilinKid authored and ti-chi-bot committed Oct 9, 2021
1 parent 7af2a24 commit 444f2c5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions parser/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/pingcap/errors v0.11.5-0.20210425183316-da1aaba5fb63
github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/stretchr/testify v1.7.0
go.uber.org/zap v1.18.1
golang.org/x/text v0.3.6
)
Expand Down
35 changes: 35 additions & 0 deletions parser/model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
. "github.com/pingcap/check"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/types"
"github.com/stretchr/testify/assert"
)

func TestT(t *testing.T) {
Expand Down Expand Up @@ -405,3 +406,37 @@ func (testModelSuite) TestDefaultValue(c *C) {
}
}
}

func TestPlacementSettingsString(t *testing.T) {
assert := assert.New(t)

settings := &PlacementSettings{
PrimaryRegion: "us-east-1",
Regions: "us-east-1,us-east-2",
Schedule: "EVEN",
}
assert.Equal("PRIMARY_REGION=\"us-east-1\" REGIONS=\"us-east-1,us-east-2\" SCHEDULE=\"EVEN\"", settings.String())

settings = &PlacementSettings{
LeaderConstraints: "[+region=bj]",
}
assert.Equal("LEADER_CONSTRAINTS=\"[+region=bj]\"", settings.String())

settings = &PlacementSettings{
Voters: 1,
VoterConstraints: "[+region=us-east-1]",
Followers: 2,
FollowerConstraints: "[+disk=ssd]",
Learners: 3,
LearnerConstraints: "[+region=us-east-2]",
}
assert.Equal("VOTERS=1 VOTER_CONSTRAINTS=\"[+region=us-east-1]\" FOLLOWERS=2 FOLLOWER_CONSTRAINTS=\"[+disk=ssd]\" LEARNERS=3 LEARNER_CONSTRAINTS=\"[+region=us-east-2]\"", settings.String())

settings = &PlacementSettings{
Voters: 3,
Followers: 2,
Learners: 1,
Constraints: "{+us-east-1:1,+us-east-2:1}",
}
assert.Equal("CONSTRAINTS=\"{+us-east-1:1,+us-east-2:1}\" VOTERS=3 FOLLOWERS=2 LEARNERS=1", settings.String())
}

0 comments on commit 444f2c5

Please sign in to comment.