github.com/containers/podman/v4@v4.9.4/pkg/machine/config_test.go (about) 1 //go:build amd64 || arm64 2 // +build amd64 arm64 3 4 package machine 5 6 import ( 7 "net" 8 "net/url" 9 "reflect" 10 "testing" 11 ) 12 13 func TestRemoteConnectionType_MakeSSHURL(t *testing.T) { 14 var ( 15 host = "foobar" 16 path = "/path/to/socket" 17 rc = "ssh" 18 username = "core" 19 ) 20 type args struct { 21 host string 22 path string 23 port string 24 userName string 25 } 26 tests := []struct { 27 name string 28 rc RemoteConnectionType 29 args args 30 want url.URL 31 }{ 32 { 33 name: "Good no port", 34 rc: "ssh", 35 args: args{ 36 host: host, 37 path: path, 38 port: "", 39 userName: username, 40 }, 41 want: url.URL{ 42 Scheme: rc, 43 User: url.User(username), 44 Host: host, 45 Path: path, 46 ForceQuery: false, 47 }, 48 }, 49 { 50 name: "Good with port", 51 rc: "ssh", 52 args: args{ 53 host: host, 54 path: path, 55 port: "222", 56 userName: username, 57 }, 58 want: url.URL{ 59 Scheme: rc, 60 User: url.User(username), 61 Host: net.JoinHostPort(host, "222"), 62 Path: path, 63 ForceQuery: false, 64 }, 65 }, 66 } 67 for _, tt := range tests { 68 t.Run(tt.name, func(t *testing.T) { 69 if got := tt.rc.MakeSSHURL(tt.args.host, tt.args.path, tt.args.port, tt.args.userName); !reflect.DeepEqual(got, tt.want) { //nolint: scopelint 70 t.Errorf("MakeSSHURL() = %v, want %v", got, tt.want) //nolint: scopelint 71 } 72 }) 73 } 74 }