github.com/kata-containers/runtime@v0.0.0-20210505125100-04f29832a923/virtcontainers/noop_agent_test.go (about) 1 // 2 // Copyright (c) 2016 Intel Corporation 3 // 4 // SPDX-License-Identifier: Apache-2.0 5 // 6 7 package virtcontainers 8 9 import ( 10 "context" 11 "testing" 12 13 "github.com/kata-containers/runtime/virtcontainers/types" 14 "github.com/stretchr/testify/assert" 15 ) 16 17 func testCreateNoopContainer() (*Sandbox, *Container, error) { 18 defer cleanUp() 19 20 contID := "100" 21 config := newTestSandboxConfigNoop() 22 23 ctx := context.Background() 24 p, err := CreateSandbox(ctx, config, nil) 25 if err != nil { 26 return nil, nil, err 27 } 28 29 contConfig := newTestContainerConfigNoop(contID) 30 31 p, c, err := CreateContainer(ctx, p.ID(), contConfig) 32 if err != nil { 33 return nil, nil, err 34 } 35 36 return p.(*Sandbox), c.(*Container), nil 37 } 38 39 func TestNoopAgentInit(t *testing.T) { 40 n := &noopAgent{} 41 sandbox := &Sandbox{} 42 assert := assert.New(t) 43 44 disableVMShutdown, err := n.init(context.Background(), sandbox, nil) 45 assert.NoError(err) 46 assert.False(disableVMShutdown) 47 } 48 49 func TestNoopAgentExec(t *testing.T) { 50 n := &noopAgent{} 51 cmd := types.Cmd{} 52 assert := assert.New(t) 53 54 sandbox, container, err := testCreateNoopContainer() 55 assert.NoError(err) 56 defer cleanUp() 57 58 _, err = n.exec(sandbox, *container, cmd) 59 assert.NoError(err) 60 } 61 62 func TestNoopAgentStartSandbox(t *testing.T) { 63 n := &noopAgent{} 64 sandbox := &Sandbox{} 65 assert := assert.New(t) 66 67 err := n.startSandbox(sandbox) 68 assert.NoError(err) 69 } 70 71 func TestNoopAgentStopSandbox(t *testing.T) { 72 n := &noopAgent{} 73 sandbox := &Sandbox{} 74 assert := assert.New(t) 75 76 err := n.stopSandbox(sandbox) 77 assert.NoError(err) 78 } 79 80 func TestNoopAgentCreateContainer(t *testing.T) { 81 n := &noopAgent{} 82 assert := assert.New(t) 83 sandbox, container, err := testCreateNoopContainer() 84 assert.NoError(err) 85 defer cleanUp() 86 87 err = n.startSandbox(sandbox) 88 assert.NoError(err) 89 90 _, err = n.createContainer(sandbox, container) 91 assert.NoError(err) 92 } 93 94 func TestNoopAgentStartContainer(t *testing.T) { 95 n := &noopAgent{} 96 assert := assert.New(t) 97 98 sandbox, container, err := testCreateNoopContainer() 99 assert.NoError(err) 100 defer cleanUp() 101 102 err = n.startContainer(sandbox, container) 103 assert.NoError(err) 104 } 105 106 func TestNoopAgentStopContainer(t *testing.T) { 107 n := &noopAgent{} 108 assert := assert.New(t) 109 sandbox, container, err := testCreateNoopContainer() 110 assert.NoError(err) 111 defer cleanUp() 112 113 err = n.stopContainer(sandbox, *container) 114 assert.NoError(err) 115 } 116 117 func TestNoopAgentStatsContainer(t *testing.T) { 118 n := &noopAgent{} 119 assert := assert.New(t) 120 sandbox, container, err := testCreateNoopContainer() 121 assert.NoError(err) 122 123 defer cleanUp() 124 _, err = n.statsContainer(sandbox, *container) 125 assert.NoError(err) 126 } 127 128 func TestNoopAgentPauseContainer(t *testing.T) { 129 n := &noopAgent{} 130 assert := assert.New(t) 131 sandbox, container, err := testCreateNoopContainer() 132 assert.NoError(err) 133 134 defer cleanUp() 135 err = n.pauseContainer(sandbox, *container) 136 assert.NoError(err) 137 } 138 139 func TestNoopAgentResumeContainer(t *testing.T) { 140 n := &noopAgent{} 141 assert := assert.New(t) 142 sandbox, container, err := testCreateNoopContainer() 143 assert.NoError(err) 144 defer cleanUp() 145 err = n.resumeContainer(sandbox, *container) 146 assert.NoError(err) 147 } 148 149 func TestNoopAgentConfigure(t *testing.T) { 150 n := &noopAgent{} 151 h := &mockHypervisor{} 152 id := "foobar" 153 sharePath := "foobarDir" 154 assert := assert.New(t) 155 err := n.configure(h, id, sharePath, true, nil) 156 assert.NoError(err) 157 } 158 159 func TestNoopAgentStartProxy(t *testing.T) { 160 assert := assert.New(t) 161 n := &noopAgent{} 162 sandbox, _, err := testCreateNoopContainer() 163 164 assert.NoError(err) 165 defer cleanUp() 166 err = n.startProxy(sandbox) 167 assert.NoError(err) 168 } 169 170 func TestNoopAgentProcessListContainer(t *testing.T) { 171 assert := assert.New(t) 172 n := &noopAgent{} 173 sandbox, container, err := testCreateNoopContainer() 174 assert.NoError(err) 175 defer cleanUp() 176 _, err = n.processListContainer(sandbox, *container, ProcessListOptions{}) 177 assert.NoError(err) 178 } 179 180 func TestNoopAgentReseedRNG(t *testing.T) { 181 assert := assert.New(t) 182 n := &noopAgent{} 183 err := n.reseedRNG([]byte{}) 184 assert.NoError(err) 185 } 186 187 func TestNoopAgentUpdateInterface(t *testing.T) { 188 assert := assert.New(t) 189 n := &noopAgent{} 190 _, err := n.updateInterface(nil) 191 assert.NoError(err) 192 } 193 194 func TestNoopAgentListInterfaces(t *testing.T) { 195 assert := assert.New(t) 196 n := &noopAgent{} 197 _, err := n.listInterfaces() 198 assert.NoError(err) 199 } 200 201 func TestNoopAgentUpdateRoutes(t *testing.T) { 202 assert := assert.New(t) 203 n := &noopAgent{} 204 _, err := n.updateRoutes(nil) 205 assert.NoError(err) 206 } 207 208 func TestNoopAgentListRoutes(t *testing.T) { 209 n := &noopAgent{} 210 assert := assert.New(t) 211 _, err := n.listRoutes() 212 assert.NoError(err) 213 } 214 215 func TestNoopAgentRSetProxy(t *testing.T) { 216 n := &noopAgent{} 217 p := &noopProxy{} 218 s := &Sandbox{} 219 assert := assert.New(t) 220 err := n.setProxy(s, p, 0, "") 221 assert.NoError(err) 222 } 223 224 func TestNoopGetAgentUrl(t *testing.T) { 225 assert := assert.New(t) 226 n := &noopAgent{} 227 228 url, err := n.getAgentURL() 229 assert.Nil(err) 230 assert.Empty(url) 231 } 232 233 func TestNoopCopyFile(t *testing.T) { 234 assert := assert.New(t) 235 n := &noopAgent{} 236 237 err := n.copyFile("", "") 238 assert.Nil(err) 239 } 240 241 func TestNoopGetOOMEvent(t *testing.T) { 242 assert := assert.New(t) 243 n := &noopAgent{} 244 245 containerID, err := n.getOOMEvent() 246 assert.Nil(err) 247 assert.Empty(containerID) 248 }