/
mount_test.go
61 lines (51 loc) · 1.23 KB
/
mount_test.go
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
// Copyright (c) 2022, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE file distributed with the sources of this project regarding your
// rights to use or distribute this software.
package siftool
import (
"os"
"os/exec"
"path/filepath"
"testing"
"github.com/sylabs/sif/v2/pkg/sif"
)
func Test_command_getMount(t *testing.T) {
if _, err := exec.LookPath("squashfuse"); err != nil {
t.Skip("squashfuse not found, skipping mount tests")
}
tests := []struct {
name string
opts commandOpts
path string
wantErr error
}{
{
name: "Empty",
path: filepath.Join(corpus, "empty.sif"),
wantErr: sif.ErrNoObjects,
},
{
name: "OneGroup",
path: filepath.Join(corpus, "one-group.sif"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
path, err := os.MkdirTemp("", "siftool-mount-*")
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
cmd := exec.Command("fusermount", "-u", path)
if err := cmd.Run(); err != nil {
t.Log(err)
}
os.RemoveAll(path)
})
c := &command{opts: tt.opts}
cmd := c.getMount()
runCommand(t, cmd, []string{tt.path, path}, tt.wantErr)
})
}
}