forked from kata-containers/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent_test.go
108 lines (82 loc) · 2.59 KB
/
agent_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright (c) 2016 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package virtcontainers
import (
"testing"
"github.com/stretchr/testify/assert"
)
func testSetAgentType(t *testing.T, value string, expected AgentType) {
var agentType AgentType
assert := assert.New(t)
err := (&agentType).Set(value)
assert.NoError(err)
assert.Equal(agentType, expected)
}
func TestSetNoopAgentType(t *testing.T) {
testSetAgentType(t, "noop", NoopAgentType)
}
func TestSetKataAgentType(t *testing.T) {
testSetAgentType(t, "kata", KataContainersAgent)
}
func TestSetUnknownAgentType(t *testing.T) {
var agentType AgentType
assert := assert.New(t)
err := (&agentType).Set("unknown")
assert.Error(err)
assert.NotEqual(agentType, NoopAgentType)
}
func testStringFromAgentType(t *testing.T, agentType AgentType, expected string) {
agentTypeStr := (&agentType).String()
assert.Equal(t, agentTypeStr, expected)
}
func TestStringFromNoopAgentType(t *testing.T) {
testStringFromAgentType(t, NoopAgentType, "noop")
}
func TestStringFromKataAgentType(t *testing.T) {
testStringFromAgentType(t, KataContainersAgent, "kata")
}
func TestStringFromUnknownAgentType(t *testing.T) {
var agentType AgentType
testStringFromAgentType(t, agentType, "")
}
func testNewAgentFromAgentType(t *testing.T, agentType AgentType, expected agent) {
ag := newAgent(agentType)
assert.Exactly(t, ag, expected)
}
func TestNewAgentFromNoopAgentType(t *testing.T) {
testNewAgentFromAgentType(t, NoopAgentType, &noopAgent{})
}
func TestNewAgentFromKataAgentType(t *testing.T) {
testNewAgentFromAgentType(t, KataContainersAgent, &kataAgent{})
}
func TestNewAgentFromUnknownAgentType(t *testing.T) {
var agentType AgentType
testNewAgentFromAgentType(t, agentType, &noopAgent{})
}
func testNewAgentConfig(t *testing.T, config SandboxConfig, expected interface{}) {
agentConfig, err := newAgentConfig(config.AgentType, config.AgentConfig)
assert.NoError(t, err)
assert.Exactly(t, agentConfig, expected)
}
func TestNewAgentConfigFromNoopAgentType(t *testing.T) {
var agentConfig interface{}
sandboxConfig := SandboxConfig{
AgentType: NoopAgentType,
AgentConfig: agentConfig,
}
testNewAgentConfig(t, sandboxConfig, agentConfig)
}
func TestNewAgentConfigFromKataAgentType(t *testing.T) {
agentConfig := KataAgentConfig{UseVSock: true}
sandboxConfig := SandboxConfig{
AgentType: KataContainersAgent,
AgentConfig: agentConfig,
}
testNewAgentConfig(t, sandboxConfig, agentConfig)
}
func TestNewAgentConfigFromUnknownAgentType(t *testing.T) {
var agentConfig interface{}
testNewAgentConfig(t, SandboxConfig{}, agentConfig)
}