77 "context"
88 "encoding/json"
99 "fmt"
10+ "net"
1011 "net/url"
1112 "path"
1213 "strings"
@@ -16,6 +17,7 @@ import (
1617 tidbinfo "github.com/pingcap/tidb/domain/infosync"
1718 "github.com/pingcap/tiproxy/lib/config"
1819 "github.com/pingcap/tiproxy/lib/util/logger"
20+ "github.com/pingcap/tiproxy/lib/util/sys"
1921 "github.com/pingcap/tiproxy/lib/util/waitgroup"
2022 "github.com/pingcap/tiproxy/pkg/manager/cert"
2123 "github.com/stretchr/testify/require"
@@ -178,6 +180,43 @@ func TestFetchTiDBTopology(t *testing.T) {
178180 }
179181}
180182
183+ func TestGetTopology (t * testing.T ) {
184+ ts := newEtcdTestSuite (t )
185+ t .Cleanup (ts .close )
186+ for _ , cas := range []struct {
187+ ip string
188+ port string
189+ non_unicast bool
190+ }{
191+ {":34" , "34" , true },
192+ {"0.0.0.0:34" , "34" , true },
193+ {"255.255.255.255:34" , "34" , true },
194+ {"239.255.255.255:34" , "34" , true },
195+ {"[FF02::1:FF47]:34" , "34" , true },
196+ {"127.0.0.1:34" , "34" , false },
197+ {"[F02::1:FF47]:34" , "34" , false },
198+ {"192.0.0.1:6049" , "6049" , false },
199+ } {
200+ is , err := ts .is .getTopologyInfo (& config.Config {
201+ Proxy : config.ProxyServer {
202+ Addr : cas .ip ,
203+ },
204+ API : config.API {
205+ Addr : cas .ip ,
206+ },
207+ })
208+ require .NoError (t , err )
209+ ip , _ , err := net .SplitHostPort (cas .ip )
210+ require .NoError (t , err )
211+ if cas .non_unicast {
212+ ip = sys .GetGlobalUnicastIP ()
213+ }
214+ require .Equal (t , ip , is .IP )
215+ require .Equal (t , cas .port , is .Port )
216+ require .Equal (t , cas .port , is .StatusPort )
217+ }
218+ }
219+
181220// Test that fetching retries when etcd server is down until the server is up again.
182221func TestEtcdServerDown4Fetch (t * testing.T ) {
183222 ts := newEtcdTestSuite (t )
0 commit comments