github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/machine/config_test.go (about)

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