Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use recognizable values for local/remote address on mock conn #10

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,16 @@ func (c *Connection) Close() error {

// LocalAddr provides a proxy to the client-side connection's LocalAddr function. This is needed to satisfy the net.Conn interface
func (c *Connection) LocalAddr() net.Addr {
return c.conn.LocalAddr()
return MockAddr{
addr: fmt.Sprintf("mock-local:%p", c),
}
}

// RemoteAddr provides a proxy to the client-side connection's RemoteAddr function. This is needed to satisfy the net.Conn interface
func (c *Connection) RemoteAddr() net.Addr {
return c.conn.RemoteAddr()
return MockAddr{
addr: fmt.Sprintf("mock-remote:%p", c),
}
}

// SetDeadline provides a proxy to the client-side connection's SetDeadline function. This is needed to satisfy the net.Conn interface
Expand Down Expand Up @@ -270,3 +274,15 @@ func (c *Connection) processOutputEntry(entry ConversationEntryOutput) error {
}
return nil
}

type MockAddr struct {
addr string
}

func (m MockAddr) Network() string {
return "mock"
}

func (m MockAddr) String() string {
return m.addr
}