Skip to content

Commit 8bbb76b

Browse files
committed
Add spec for BasicSocket#local_address on Socket.pair UNIX sockets
* Also tests creating an Addrinfo with empty-path UNIX sockets.
1 parent 4f5b7c5 commit 8bbb76b

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

spec/ruby/library/socket/unixsocket/local_address_spec.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,50 @@
4747
end
4848
end
4949
end
50+
51+
with_feature :unix_socket do
52+
describe 'UNIXSocket#local_address with a UNIX socket pair' do
53+
before :each do
54+
@sock, @sock2 = Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
55+
end
56+
57+
after :each do
58+
@sock.close
59+
@sock2.close
60+
end
61+
62+
it 'returns an Addrinfo' do
63+
@sock.local_address.should be_an_instance_of(Addrinfo)
64+
end
65+
66+
describe 'the returned Addrinfo' do
67+
it 'uses AF_UNIX as the address family' do
68+
@sock.local_address.afamily.should == Socket::AF_UNIX
69+
end
70+
71+
it 'uses PF_UNIX as the protocol family' do
72+
@sock.local_address.pfamily.should == Socket::PF_UNIX
73+
end
74+
75+
it 'uses SOCK_STREAM as the socket type' do
76+
@sock.local_address.socktype.should == Socket::SOCK_STREAM
77+
end
78+
79+
it 'raises SocketError for #ip_address' do
80+
-> {
81+
@sock.local_address.ip_address
82+
}.should raise_error(SocketError, "need IPv4 or IPv6 address")
83+
end
84+
85+
it 'raises SocketError for #ip_port' do
86+
-> {
87+
@sock.local_address.ip_port
88+
}.should raise_error(SocketError, "need IPv4 or IPv6 address")
89+
end
90+
91+
it 'uses 0 as the protocol' do
92+
@sock.local_address.protocol.should == 0
93+
end
94+
end
95+
end
96+
end

0 commit comments

Comments
 (0)