aboutsummaryrefslogtreecommitdiff
path: root/pkg/machine/config_test.go
blob: ca08660b90ca455c8547961667f5feb372c304c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//go:build amd64 || arm64
// +build amd64 arm64

package machine

import (
	"net"
	"net/url"
	"reflect"
	"testing"
)

func TestRemoteConnectionType_MakeSSHURL(t *testing.T) {
	var (
		host     = "foobar"
		path     = "/path/to/socket"
		rc       = "ssh"
		username = "core"
	)
	type args struct {
		host     string
		path     string
		port     string
		userName string
	}
	tests := []struct {
		name string
		rc   RemoteConnectionType
		args args
		want url.URL
	}{
		{
			name: "Good no port",
			rc:   "ssh",
			args: args{
				host:     host,
				path:     path,
				port:     "",
				userName: username,
			},
			want: url.URL{
				Scheme:     rc,
				User:       url.User(username),
				Host:       host,
				Path:       path,
				ForceQuery: false,
			},
		},
		{
			name: "Good with port",
			rc:   "ssh",
			args: args{
				host:     host,
				path:     path,
				port:     "222",
				userName: username,
			},
			want: url.URL{
				Scheme:     rc,
				User:       url.User(username),
				Host:       net.JoinHostPort(host, "222"),
				Path:       path,
				ForceQuery: false,
			},
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := tt.rc.MakeSSHURL(tt.args.host, tt.args.path, tt.args.port, tt.args.userName); !reflect.DeepEqual(got, tt.want) { //nolint: scopelint
				t.Errorf("MakeSSHURL() = %v, want %v", got, tt.want) //nolint: scopelint
			}
		})
	}
}