mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-11 10:50:14 +08:00
Implemented GetFreePort utility function to get free port for tests. Updated ACL and PubSub tests to use new GetFreePort functions instead of hardcoded ports
This commit is contained in:
@@ -410,3 +410,20 @@ func CompareNestedStringArrays(got [][]string, want [][]string) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func GetFreePort() (int, error) {
|
||||
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
l, err := net.ListenTCP("tcp", addr)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer func() {
|
||||
_ = l.Close()
|
||||
}()
|
||||
|
||||
return l.Addr().(*net.TCPAddr).Port, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user