forked from containers/podman
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request containers#13674 from baude/refactor1
Machine refactor - part 1
- Loading branch information
Showing
6 changed files
with
318 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
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 | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package qemu | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestMachineFile_GetPath(t *testing.T) { | ||
path := "/var/tmp/podman/my.sock" | ||
sym := "/tmp/podman/my.sock" | ||
type fields struct { | ||
Path string | ||
Symlink *string | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
want string | ||
}{ | ||
{ | ||
name: "Original path", | ||
fields: fields{path, nil}, | ||
want: path, | ||
}, | ||
{ | ||
name: "Symlink over path", | ||
fields: fields{ | ||
Path: path, | ||
Symlink: &sym, | ||
}, | ||
want: sym, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
m := &MachineFile{ | ||
Path: tt.fields.Path, //nolint: scopelint | ||
Symlink: tt.fields.Symlink, //nolint: scopelint | ||
} | ||
if got := m.GetPath(); got != tt.want { //nolint: scopelint | ||
t.Errorf("GetPath() = %v, want %v", got, tt.want) //nolint: scopelint | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestNewMachineFile(t *testing.T) { | ||
p := "/var/tmp/podman/my.sock" | ||
sym := "/tmp/podman/my.sock" | ||
empty := "" | ||
|
||
m := MachineFile{ | ||
Path: p, | ||
Symlink: nil, | ||
} | ||
type args struct { | ||
path string | ||
symlink *string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *MachineFile | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "Good", | ||
args: args{path: p}, | ||
want: &m, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Good with Symlink", | ||
args: args{p, &sym}, | ||
want: &MachineFile{p, &sym}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Bad path name", | ||
args: args{empty, nil}, | ||
want: nil, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "Bad symlink name", | ||
args: args{p, &empty}, | ||
want: nil, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := NewMachineFile(tt.args.path, tt.args.symlink) //nolint: scopelint | ||
if (err != nil) != tt.wantErr { //nolint: scopelint | ||
t.Errorf("NewMachineFile() error = %v, wantErr %v", err, tt.wantErr) //nolint: scopelint | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { //nolint: scopelint | ||
t.Errorf("NewMachineFile() got = %v, want %v", got, tt.want) //nolint: scopelint | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.