machine refactor 3: add symlinks for sockets

to avoid errors on macos, we use symlinks to long socket names.

Fixes: #12751
Fixes: #13609

Signed-off-by: Brent Baude <bbaude@redhat.com>

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
Brent Baude
2022-03-31 16:11:04 -05:00
parent 5e821f7339
commit 9c72ea3434
3 changed files with 98 additions and 59 deletions

View File

@ -1,8 +1,12 @@
package qemu
import (
"os"
"path/filepath"
"reflect"
"testing"
"github.com/containers/podman/v4/test/utils"
)
func TestMachineFile_GetPath(t *testing.T) {
@ -45,10 +49,30 @@ func TestMachineFile_GetPath(t *testing.T) {
}
func TestNewMachineFile(t *testing.T) {
p := "/var/tmp/podman/my.sock"
sym := "/tmp/podman/my.sock"
empty := ""
homedir, err := os.MkdirTemp("/tmp", "homedir")
if err != nil {
panic(err)
}
defer os.RemoveAll(homedir)
longTemp, err := os.MkdirTemp("/tmp", "tmpdir")
if err != nil {
panic(err)
}
defer os.RemoveAll(longTemp)
oldhome := os.Getenv("HOME")
os.Setenv("HOME", homedir) //nolint: tenv
defer os.Setenv("HOME", oldhome)
p := "/var/tmp/podman/my.sock"
longp := filepath.Join(longTemp, utils.RandomString(100), "my.sock")
os.MkdirAll(filepath.Dir(longp), 0755)
f, _ := os.Create(longp)
f.Close()
sym := "my.sock"
longSym := filepath.Join(homedir, ".podman", sym)
m := MachineFile{
Path: p,
Symlink: nil,
@ -70,9 +94,9 @@ func TestNewMachineFile(t *testing.T) {
wantErr: false,
},
{
name: "Good with Symlink",
name: "Good with short symlink",
args: args{p, &sym},
want: &MachineFile{p, &sym},
want: &MachineFile{p, nil},
wantErr: false,
},
{
@ -87,6 +111,12 @@ func TestNewMachineFile(t *testing.T) {
want: nil,
wantErr: true,
},
{
name: "Good with long symlink",
args: args{longp, &sym},
want: &MachineFile{longp, &longSym},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {