diff options
Diffstat (limited to 'pkg/machine/qemu/config_test.go')
-rw-r--r-- | pkg/machine/qemu/config_test.go | 38 |
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) { |