forked from kata-containers/shim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shim_test.go
64 lines (48 loc) · 1.3 KB
/
shim_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
// Copyright 2017 HyperHQ Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
package main
import (
"os/signal"
"sync"
"testing"
"github.com/kr/pty"
"github.com/stretchr/testify/assert"
)
func TestNewShim(t *testing.T) {
agent := testSetup(t)
defer testTearDown(agent)
contID := "foobarContainer"
execID := "testExec"
err := agent.addContainer(contID, execID)
assert.Nil(t, err, "%s", err)
shim, err := newShim(mockSockAddr, contID, execID)
assert.Nil(t, err, "%s", err)
defer shim.agent.Close()
_, err = newShim(badMockAddr, contID, execID)
assert.NotNil(t, err, "New shim with wrong socket address should fail")
}
func TestShimOps(t *testing.T) {
agent := testSetup(t)
defer testTearDown(agent)
contID := "foobarContainer"
execID := "testExec"
err := agent.addContainer(contID, execID)
assert.Nil(t, err, "%s", err)
shim, err := newShim(mockSockAddr, contID, execID)
assert.Nil(t, err, "%s", err)
defer shim.agent.Close()
_, tty, err := pty.Open()
assert.Nil(t, err, "%s", err)
defer tty.Close()
shim.resizeTty(tty)
wg := &sync.WaitGroup{}
shim.proxyStdio(wg, true)
sigc := shim.forwardAllSignals()
defer signal.Stop(sigc)
shim.monitorTtySize(tty)
status, err := shim.wait()
assert.Nil(t, err, "%s", err)
assert.Equal(t, status, int32(0), "process fail status %d", status)
}