Skip to content

Commit 6894c0c

Browse files
authored
config: add test for balance configs (#1048)
1 parent 4c29041 commit 6894c0c

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

lib/config/balance_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2025 PingCAP, Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package config
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/require"
10+
)
11+
12+
func TestCheckBalance(t *testing.T) {
13+
balances := []Balance{
14+
{
15+
Policy: "test",
16+
},
17+
{
18+
RoutingPolicy: "test",
19+
},
20+
{
21+
Status: Factor{MigrationsPerSecond: -1},
22+
},
23+
{
24+
Health: Factor{MigrationsPerSecond: -1},
25+
},
26+
{
27+
Memory: Factor{MigrationsPerSecond: -1},
28+
},
29+
{
30+
CPU: Factor{MigrationsPerSecond: -1},
31+
},
32+
{
33+
Location: Factor{MigrationsPerSecond: -1},
34+
},
35+
{
36+
ConnCount: ConnCountFactor{Factor: Factor{MigrationsPerSecond: -1}},
37+
},
38+
{
39+
ConnCount: ConnCountFactor{CountRatioThreshold: -1},
40+
},
41+
}
42+
43+
for i, balance := range balances {
44+
require.Error(t, balance.Check(), "%d", i)
45+
}
46+
47+
balance := Balance{}
48+
require.NoError(t, (&balance).Check())
49+
balance = DefaultBalance()
50+
require.NoError(t, (&balance).Check())
51+
}

0 commit comments

Comments
 (0)