forked from kata-containers/shim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shim_test.go
67 lines (51 loc) · 1.44 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
65
66
67
// Copyright 2017 HyperHQ Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
package main
import (
"context"
"os"
"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(context.Background(), mockSockAddr, contID, execID)
assert.Nil(t, err, "%s", err)
defer shim.agent.Close()
_, err = newShim(context.Background(), 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(context.Background(), 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.handleSignals(context.Background(), os.Stdin)
defer signal.Stop(sigc)
status, err := shim.wait()
assert.Nil(t, err, "%s", err)
assert.Equal(t, status, int32(0), "process fail status %d", status)
// wait for go routines started by proxyStdio() to end
wg.Wait()
}