forked from kata-containers/kata-containers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fc_test.go
84 lines (62 loc) · 1.84 KB
/
fc_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//go:build linux
// +build linux
// Copyright (c) 2019 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package virtcontainers
import (
"strings"
"testing"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
"github.com/stretchr/testify/assert"
)
func TestFCGenerateSocket(t *testing.T) {
assert := assert.New(t)
fc := firecracker{}
i, err := fc.GenerateSocket("a")
assert.NoError(err)
assert.NotNil(i)
hvsock, ok := i.(types.HybridVSock)
assert.True(ok)
assert.NotEmpty(hvsock.UdsPath)
// Path must be absolute
assert.True(strings.HasPrefix(hvsock.UdsPath, "/"))
assert.NotZero(hvsock.Port)
}
func TestFCTruncateID(t *testing.T) {
assert := assert.New(t)
fc := firecracker{}
testLongID := "3ef98eb7c6416be11e0accfed2f4e6560e07f8e33fa8d31922fd4d61747d7ead"
expectedID := "3ef98eb7c6416be11e0accfed2f4e656"
id := fc.truncateID(testLongID)
assert.Equal(expectedID, id)
testShortID := "3ef98eb7c6416be11"
expectedID = "3ef98eb7c6416be11"
id = fc.truncateID(testShortID)
assert.Equal(expectedID, id)
}
func TestFCParseVersion(t *testing.T) {
assert := assert.New(t)
fc := firecracker{}
for rawVersion, v := range map[string]string{"Firecracker v0.23.1": "0.23.1", "Firecracker v0.25.0\nSupported snapshot data format versions: 0.23.0": "0.25.0"} {
parsedVersion, err := fc.parseVersion(rawVersion)
assert.NoError(err)
assert.Equal(parsedVersion, v)
}
}
func TestFcSetConfig(t *testing.T) {
assert := assert.New(t)
config := HypervisorConfig{
HypervisorPath: "/some/where/firecracker",
KernelPath: "/some/where/kernel",
ImagePath: "/some/where/image",
JailerPath: "/some/where/jailer",
Debug: true,
}
fc := firecracker{}
assert.Equal(fc.config, HypervisorConfig{})
err := fc.setConfig(&config)
assert.NoError(err)
assert.Equal(fc.config, config)
}