44 "encoding/json"
55 "errors"
66 "fmt"
7+ "io/fs"
78 "net"
89 "os"
910 "strconv"
@@ -239,7 +240,7 @@ func TestPauseMetadata(t *testing.T) {
239240 test .Equal (t , false , isPaused (nsqd , 0 , 0 ))
240241}
241242
242- func mustStartNSQLookupd (opts * nsqlookupd.Options ) (* net.TCPAddr , * net.TCPAddr , * nsqlookupd.NSQLookupd ) {
243+ func mustStartNSQLookupd (opts * nsqlookupd.Options ) (net.Addr , net.Addr , * nsqlookupd.NSQLookupd ) {
243244 opts .TCPAddress = "127.0.0.1:0"
244245 opts .HTTPAddress = "127.0.0.1:0"
245246 lookupd , err := nsqlookupd .New (opts )
@@ -361,15 +362,15 @@ func TestCluster(t *testing.T) {
361362
362363 test .Equal (t , hostname , topicData [0 ].Hostname )
363364 test .Equal (t , "127.0.0.1" , topicData [0 ].BroadcastAddress )
364- test .Equal (t , nsqd .RealTCPAddr ().Port , topicData [0 ].TCPPort )
365+ test .Equal (t , nsqd .RealTCPAddr ().( * net. TCPAddr ). Port , topicData [0 ].TCPPort )
365366 test .Equal (t , false , topicData [0 ].Tombstoned )
366367
367368 channelData := d ["channel:" + topicName + ":ch" ]
368369 test .Equal (t , 1 , len (channelData ))
369370
370371 test .Equal (t , hostname , channelData [0 ].Hostname )
371372 test .Equal (t , "127.0.0.1" , channelData [0 ].BroadcastAddress )
372- test .Equal (t , nsqd .RealTCPAddr ().Port , channelData [0 ].TCPPort )
373+ test .Equal (t , nsqd .RealTCPAddr ().( * net. TCPAddr ). Port , channelData [0 ].TCPPort )
373374 test .Equal (t , false , channelData [0 ].Tombstoned )
374375
375376 var lr struct {
@@ -388,7 +389,7 @@ func TestCluster(t *testing.T) {
388389 test .Equal (t , 1 , len (lr .Producers ))
389390 test .Equal (t , hostname , lr .Producers [0 ].Hostname )
390391 test .Equal (t , "127.0.0.1" , lr .Producers [0 ].BroadcastAddress )
391- test .Equal (t , nsqd .RealTCPAddr ().Port , lr .Producers [0 ].TCPPort )
392+ test .Equal (t , nsqd .RealTCPAddr ().( * net. TCPAddr ). Port , lr .Producers [0 ].TCPPort )
392393 test .Equal (t , 1 , len (lr .Channels ))
393394 test .Equal (t , "ch" , lr .Channels [0 ])
394395
@@ -438,3 +439,23 @@ func TestSetHealth(t *testing.T) {
438439 test .Equal (t , "OK" , nsqd .GetHealth ())
439440 test .Equal (t , true , nsqd .IsHealthy ())
440441}
442+
443+ func TestUnixSocketStartup (t * testing.T ) {
444+ isSocket := func (path string ) bool {
445+ fileInfo , err := os .Stat (path )
446+ if err != nil {
447+ return false
448+ }
449+ return fileInfo .Mode ().Type () == fs .ModeSocket
450+ }
451+
452+ opts := NewOptions ()
453+ opts .Logger = test .NewTestLogger (t )
454+
455+ _ , _ , nsqd := mustUnixSocketStartNSQD (opts )
456+ defer os .RemoveAll (opts .DataPath )
457+ defer nsqd .Exit ()
458+
459+ test .Equal (t , isSocket (opts .TCPAddress ), true )
460+ test .Equal (t , isSocket (opts .HTTPAddress ), true )
461+ }
0 commit comments