@@ -270,6 +270,7 @@ Ap157PUHTriSnxyMF2Sb3EhX/rQkmbnbCqqygHC14iBy8MrKzLG00X6BelZV5n0D
270270RKjnkiEZeG4+G91Xu7+HmcBLwV86k5I+tXK9O1Okomr6Zry8oqVcxU5TB6VRS+rA
271271ubwF00Drdvk2+kDZfxIM137nBiy7wgCJi2Ksm5ihN3dUF6Q0oNPl
272272-----END RSA PRIVATE KEY-----`
273+ osWindows = "windows"
273274)
274275
275276// MockOsFs mockable OsFs
@@ -523,7 +524,7 @@ func TestResolvePathErrors(t *testing.T) {
523524 assert .EqualError (t , err , common .ErrGenericFailure .Error ())
524525 }
525526
526- if runtime .GOOS != "windows" {
527+ if runtime .GOOS != osWindows {
527528 user .HomeDir = filepath .Clean (os .TempDir ())
528529 connection .User = user
529530 fs := vfs .NewOsFs ("connID" , connection .User .HomeDir , "" , nil )
@@ -1740,3 +1741,68 @@ func TestGetCacheExpirationTime(t *testing.T) {
17401741 c .ExpirationTime = 1
17411742 assert .False (t , c .getExpirationTime ().IsZero ())
17421743}
1744+
1745+ func TestBindingGetAddress (t * testing.T ) {
1746+ tests := []struct {
1747+ name string
1748+ binding Binding
1749+ want string
1750+ }{
1751+ {
1752+ name : "IP address with port" ,
1753+ binding : Binding {Address : "127.0.0.1" , Port : 8080 },
1754+ want : "127.0.0.1:8080" ,
1755+ },
1756+ {
1757+ name : "Unix socket path (no port)" ,
1758+ binding : Binding {Address : "/tmp/app.sock" , Port : 0 },
1759+ want : "/tmp/app.sock" ,
1760+ },
1761+ }
1762+
1763+ for _ , tt := range tests {
1764+ t .Run (tt .name , func (t * testing.T ) {
1765+ if got := tt .binding .GetAddress (); got != tt .want {
1766+ t .Errorf ("GetAddress() = %v, want %v" , got , tt .want )
1767+ }
1768+ })
1769+ }
1770+ }
1771+
1772+ func TestBindingIsValid (t * testing.T ) {
1773+ tests := []struct {
1774+ name string
1775+ binding Binding
1776+ want bool
1777+ }{
1778+ {
1779+ name : "Valid: Positive port" ,
1780+ binding : Binding {Address : "127.0.0.1" , Port : 10080 },
1781+ want : true ,
1782+ },
1783+ {
1784+ name : "Valid: Absolute path on Unix (non-Windows)" ,
1785+ binding : Binding {Address : "/var/run/app.sock" , Port : 0 },
1786+ // This test outcome is dynamic based on the OS
1787+ want : runtime .GOOS != osWindows ,
1788+ },
1789+ {
1790+ name : "Invalid: Port 0 and relative path" ,
1791+ binding : Binding {Address : "relative/path" , Port : 0 },
1792+ want : false ,
1793+ },
1794+ {
1795+ name : "Invalid: Empty address and port 0" ,
1796+ binding : Binding {Address : "" , Port : 0 },
1797+ want : false ,
1798+ },
1799+ }
1800+
1801+ for _ , tt := range tests {
1802+ t .Run (tt .name , func (t * testing.T ) {
1803+ if got := tt .binding .IsValid (); got != tt .want {
1804+ t .Errorf ("IsValid() = %v, want %v" , got , tt .want )
1805+ }
1806+ })
1807+ }
1808+ }
0 commit comments