forked from kata-containers/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mockcontainer_test.go
155 lines (134 loc) · 3.25 KB
/
mockcontainer_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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//
// Copyright (c) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package main
import (
"github.com/opencontainers/runc/libcontainer/cgroups"
"syscall"
"testing"
"github.com/opencontainers/runc/libcontainer"
"github.com/opencontainers/runc/libcontainer/configs"
"github.com/stretchr/testify/assert"
)
func TestMockContainerID(t *testing.T) {
assert := assert.New(t)
expectedContID := "abc"
m := &mockContainer{id: expectedContID}
id := m.ID()
assert.Equal(expectedContID, id)
}
func TestMockContainerStatus(t *testing.T) {
assert := assert.New(t)
expectedStatus := libcontainer.Running
m := &mockContainer{status: expectedStatus}
status, err := m.Status()
assert.NoError(err)
assert.Equal(expectedStatus, status)
}
func TestMockContainerState(t *testing.T) {
assert := assert.New(t)
m := &mockContainer{}
st, err := m.State()
assert.NoError(err)
assert.Nil(st)
}
func TestMockContainerConfig(t *testing.T) {
assert := assert.New(t)
m := &mockContainer{}
cfg := m.Config()
assert.NotNil(cfg)
}
func TestMockContainerProcesses(t *testing.T) {
assert := assert.New(t)
expectedProcesses := []int{1}
m := &mockContainer{processes: expectedProcesses}
p, err := m.Processes()
assert.NoError(err)
assert.Equal(expectedProcesses, p)
}
func TestMockContainerStats(t *testing.T) {
assert := assert.New(t)
expectedStats := &libcontainer.Stats{
CgroupStats: &cgroups.Stats{},
}
m := &mockContainer{stats: *expectedStats}
st, err := m.Stats()
assert.NoError(err)
assert.Equal(expectedStats, st)
}
func TestMockContainerSet(t *testing.T) {
assert := assert.New(t)
m := &mockContainer{}
err := m.Set(configs.Config{})
assert.NoError(err)
}
func TestMockContainerStart(t *testing.T) {
assert := assert.New(t)
m := &mockContainer{}
err := m.Start(nil)
assert.NoError(err)
}
func TestMockContainerRun(t *testing.T) {
assert := assert.New(t)
m := &mockContainer{}
err := m.Run(nil)
assert.NoError(err)
}
func TestMockContainerDestroy(t *testing.T) {
assert := assert.New(t)
m := &mockContainer{}
err := m.Destroy()
assert.NoError(err)
}
func TestMockContainerSignal(t *testing.T) {
assert := assert.New(t)
m := &mockContainer{}
err := m.Signal(syscall.SIGKILL, true)
assert.NoError(err)
}
func TestMockContainerExec(t *testing.T) {
assert := assert.New(t)
m := &mockContainer{}
err := m.Exec()
assert.NoError(err)
}
func TestMockContainerCheckpoint(t *testing.T) {
assert := assert.New(t)
m := &mockContainer{}
err := m.Checkpoint(nil)
assert.NoError(err)
}
func TestMockContainerRestore(t *testing.T) {
assert := assert.New(t)
m := &mockContainer{}
err := m.Restore(nil, nil)
assert.NoError(err)
}
func TestMockContainerPause(t *testing.T) {
assert := assert.New(t)
m := &mockContainer{}
err := m.Pause()
assert.NoError(err)
}
func TestMockContainerResume(t *testing.T) {
assert := assert.New(t)
m := &mockContainer{}
err := m.Resume()
assert.NoError(err)
}
func TestMockContainerNotifyOOM(t *testing.T) {
assert := assert.New(t)
m := &mockContainer{}
c, err := m.NotifyOOM()
assert.NoError(err)
assert.Nil(c)
}
func TestMockContainerNotifyMemoryPressure(t *testing.T) {
assert := assert.New(t)
m := &mockContainer{}
c, err := m.NotifyMemoryPressure(libcontainer.LowPressure)
assert.NoError(err)
assert.Nil(c)
}