summaryrefslogtreecommitdiff
path: root/pkg/machine/qemu/config_test.go
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2022-03-31 16:11:04 -0500
committerBrent Baude <bbaude@redhat.com>2022-04-05 13:14:28 -0500
commit9c72ea343435e502753bea9cfb0611cbc5dc91c1 (patch)
tree1104dd8e0857947481fc8b72d6df5463fb0cc5de /pkg/machine/qemu/config_test.go
parent5e821f7339bcfe7b653a2867c7637527d29efd79 (diff)
downloadpodman-9c72ea343435e502753bea9cfb0611cbc5dc91c1.tar.gz
podman-9c72ea343435e502753bea9cfb0611cbc5dc91c1.tar.bz2
podman-9c72ea343435e502753bea9cfb0611cbc5dc91c1.zip
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>
Diffstat (limited to 'pkg/machine/qemu/config_test.go')
-rw-r--r--pkg/machine/qemu/config_test.go38
1 files changed, 34 insertions, 4 deletions
diff --git a/pkg/machine/qemu/config_test.go b/pkg/machine/qemu/config_test.go
index e3e7437b5..264de9ae8 100644
--- a/pkg/machine/qemu/config_test.go
+++ b/pkg/machine/qemu/config_test.go
@@ -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) {