Skip to content

Commit

Permalink
Merge pull request #8217 from planetscale/raw-conn
Browse files Browse the repository at this point in the history
Expose inner net.Conn to be able to write better unit tests
  • Loading branch information
systay authored Jun 2, 2021
2 parents e1c70dd + f4b9d27 commit 02dfc25
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions go/mysql/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1493,3 +1493,8 @@ func (c *Conn) GetTLSClientCerts() []*x509.Certificate {
}
return nil
}

// GetRawConn returns the raw net.Conn for nefarious purposes.
func (c *Conn) GetRawConn() net.Conn {
return c.conn
}
11 changes: 11 additions & 0 deletions go/mysql/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ func verifyPacketComms(t *testing.T, cConn, sConn *Conn, data []byte) {
}
}

func TestRawConnection(t *testing.T) {
listener, sConn, cConn := createSocketPair(t)
defer func() {
listener.Close()
sConn.Close()
cConn.Close()
}()
assert.IsType(t, &net.TCPConn{}, sConn.GetRawConn())
assert.IsType(t, &net.TCPConn{}, cConn.GetRawConn())
}

func TestPackets(t *testing.T) {
listener, sConn, cConn := createSocketPair(t)
defer func() {
Expand Down

0 comments on commit 02dfc25

Please sign in to comment.