11package server
22
33import (
4+ "bytes"
5+ "strings"
46 "testing"
57 "time"
68
@@ -27,3 +29,34 @@ func TestFormatTelegrafLine(t *testing.T) {
2729 line := formatTelegrafLine ("host name,prod=1" , 10 , 15 , time .Unix (0 , 1778837100123456789 ))
2830 assert .Equal (t , "git-queue,host=host\\ name\\ ,prod\\ =1 active=10i,queued=15i 1778837100123456789\n " , line )
2931}
32+
33+ func TestPrintConnections_DefaultRemoteWithoutPort (t * testing.T ) {
34+ var b bytes.Buffer
35+ err := PrintConnections (& b , []ConnectionInfo {{
36+ Index : 1 ,
37+ RemoteAddr : "192.0.2.12" ,
38+ RemotePort : "443" ,
39+ Path : "/repo.git/git-upload-pack" ,
40+ Connected : time .Date (2026 , 5 , 16 , 12 , 0 , 0 , 0 , time .UTC ),
41+ }}, false )
42+ require .NoError (t , err )
43+
44+ out := b .String ()
45+ assert .Contains (t , out , "192.0.2.12" )
46+ assert .NotContains (t , out , "192.0.2.12:443" )
47+ }
48+
49+ func TestPrintConnections_WithPort (t * testing.T ) {
50+ var b bytes.Buffer
51+ err := PrintConnections (& b , []ConnectionInfo {{
52+ Index : 1 ,
53+ RemoteAddr : "192.0.2.12" ,
54+ RemotePort : "443" ,
55+ Path : "/repo.git/git-upload-pack" ,
56+ Connected : time .Date (2026 , 5 , 16 , 12 , 0 , 0 , 0 , time .UTC ),
57+ }}, true )
58+ require .NoError (t , err )
59+
60+ out := b .String ()
61+ assert .True (t , strings .Contains (out , "192.0.2.12:443" ) || strings .Contains (out , "[192.0.2.12]:443" ))
62+ }
0 commit comments