Skip to content

Commit

Permalink
remove deprecated code usage from standard fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
rekby committed Aug 9, 2024
1 parent b6435f4 commit d00fb76
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions sf/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ func LocalTCPListener(e fixenv.Env) *net.TCPListener {
}

func LocalTCPListenerNamed(e fixenv.Env, name string) *net.TCPListener {
return e.CacheWithCleanup(name, nil, func() (res interface{}, cleanup fixenv.FixtureCleanupFunc, err error) {
f := func() (*fixenv.Result, error) {
listener, err := net.Listen("tcp", "localhost:0")
clean := func() {
_ = listener.Close()
if listener != nil {
_ = listener.Close()
}
}
return listener, clean, err
}).(*net.TCPListener)
return fixenv.NewResultWithCleanup(listener, clean), err
}
return e.CacheResult(f, fixenv.CacheOptions{CacheKey: name}).(*net.TCPListener)
}

0 comments on commit d00fb76

Please sign in to comment.