func TestGetServerConnection(t *testing.T) { oldAddr, oldPort := config.GetListenParams() config.SetListenParams("127.0.0.1", 45432) defer config.SetListenParams(oldAddr, oldPort) l, err := getServerConnection() defer l.Close() assert.NotNil(t, l) assert.NoError(t, err) assert.Equal(t, "tcp", l.Addr().Network()) assert.Equal(t, "127.0.0.1:45432", l.Addr().String()) }
func getServerConnection() (net.Listener, error) { host, port := config.GetListenParams() addr := fmt.Sprintf("%s:%d", host, port) return net.Listen("tcp", addr) }