https://github.com/connorkuehl/netmem
Package netmem provides a completely in-memory net.Listener that brokers net.Conns based on net.Pipe to facilitate broader end-to-end tests of server packages from within a unit test
https://github.com/connorkuehl/netmem
Last synced: 22 days ago
JSON representation
Package netmem provides a completely in-memory net.Listener that brokers net.Conns based on net.Pipe to facilitate broader end-to-end tests of server packages from within a unit test
- Host: GitHub
- URL: https://github.com/connorkuehl/netmem
- Owner: connorkuehl
- License: mit
- Created: 2022-10-24T01:38:04.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-24T01:57:13.000Z (over 2 years ago)
- Last Synced: 2025-02-12T18:55:55.222Z (2 months ago)
- Language: Go
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# netmem
Package netmem provides a completely in-memory Listener that brokers net.Conns
based on net.Pipe.Its primary use case is to enable broader end-to-end testing functionality
from within the scope of a unit test. For example, to test the public
implementation of a client package against a fully-functioning instance of
the server package.Generally speaking, if your server implementation allows you to inject
its net.Listener, you can inject this instead and it will accept in-memory
network connections.```go
l, _ := netmem.Listen()
defer l.Close()go func() {
conn, _ := l.Accept()
defer conn.Close()
_, _ = io.WriteString(conn, "Greetings, friend!")
}()cli, _ := l.(*netmem.Listener).Dial()
defer cli.Close()var rsp strings.Builder
_, _ = io.Copy(&rsp, cli)
fmt.Printf("Incoming transmission: %q\n", rsp.String())
``````console
$ go run ./examples/readme
Incoming transmission: "Greetings, friend!"
```