14
14
package vm
15
15
16
16
import (
17
+ "io/ioutil"
18
+ "os"
19
+ "path"
17
20
"strings"
18
21
"testing"
19
22
20
23
"github.com/stretchr/testify/assert"
24
+ "github.com/stretchr/testify/require"
21
25
)
22
26
23
27
var invalidContainerIDs = []string {"" , "id?" , "*" , "id/1" , "id\\ " }
24
28
25
29
func TestShimDir (t * testing.T ) {
30
+ runDir , err := ioutil .TempDir ("" , "run" )
31
+ require .NoError (t , err )
32
+ defer os .RemoveAll (runDir )
33
+
26
34
tests := []struct {
27
35
name string
28
36
ns string
@@ -40,22 +48,22 @@ func TestShimDir(t *testing.T) {
40
48
{name : "id with ?" , ns : "test" , id : "?" , outErr : `invalid vm id: identifier "?" must match` },
41
49
{name : "id with *" , ns : "test" , id : "*" , outErr : `invalid vm id: identifier "*" must match` },
42
50
{name : "id with ," , ns : "test" , id : "," , outErr : `invalid vm id: identifier "," must match` },
43
- {name : "valid" , ns : "ns" , id : "1" , outDir : "/run/firecracker-containerd/ ns/1" },
44
- {name : "valid with dashes" , ns : "test-123" , id : "123-456" , outDir : "/run/firecracker-containerd/ test-123/123-456" },
45
- {name : "valid with dots" , ns : "test.123" , id : "123.456" , outDir : "/run/firecracker-containerd/ test.123/123.456" },
51
+ {name : "valid" , ns : "ns" , id : "1" , outDir : "ns/1" },
52
+ {name : "valid with dashes" , ns : "test-123" , id : "123-456" , outDir : "test-123/123-456" },
53
+ {name : "valid with dots" , ns : "test.123" , id : "123.456" , outDir : "test.123/123.456" },
46
54
}
47
55
48
56
for _ , tc := range tests {
49
57
test := tc
50
58
t .Run (test .name , func (t * testing.T ) {
51
- dir , err := ShimDir ( test .ns , test .id )
59
+ dir , err := shimDir ( runDir , test .ns , test .id )
52
60
53
61
if test .outErr != "" {
54
62
assert .Error (t , err )
55
63
assert .True (t , strings .Contains (err .Error (), test .outErr ), err .Error ())
56
64
} else {
57
65
assert .NoError (t , err )
58
- assert .EqualValues (t , dir , test .outDir )
66
+ assert .EqualValues (t , dir , path . Join ( runDir , test .outDir ) )
59
67
}
60
68
})
61
69
}
0 commit comments