forked from kata-containers/shim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipe_test.go
48 lines (36 loc) · 1.39 KB
/
pipe_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
// Copyright 2017 HyperHQ Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestPipe(t *testing.T) {
agent := testSetup(t)
defer testTearDown(agent)
containerID := "testContainer"
execID := "testExec"
err := agent.addContainer(containerID, execID)
assert.Nil(t, err, "failed to add new container: %s", err)
inPipe, outPipe, errPipe := shimStdioPipe(agent.ctx, agent.client, containerID, execID)
buf := []byte("foobar")
size, err := inPipe.Write(buf[:])
assert.Nil(t, err, "failed to write stdin pipe: %s", err)
assert.Equal(t, size, len(buf), "unmatched write stdin pipe len %d:%d", len(buf), size)
size, err = outPipe.Read(buf)
assert.Nil(t, err, "failed to read stdout pipe: %s", err)
assert.Equal(t, size, 0, "unmatched write stdin pipe len %d:%d", 0, size)
size, err = errPipe.Read(buf)
assert.Nil(t, err, "failed to read stderr pipe: %s", err)
assert.Equal(t, size, 0, "unmatched write stdin pipe len %d:%d", 0, size)
// wrong process
inPipe, outPipe, errPipe = shimStdioPipe(agent.ctx, agent.client, containerID, execID+"foobar")
_, err = inPipe.Write(buf[:])
assert.NotNil(t, err, "Unexpected success writing stdin pipe")
_, err = outPipe.Read(buf)
assert.NotNil(t, err, "Unexpected success reading stdout pipe")
_, err = errPipe.Read(buf)
assert.NotNil(t, err, "Unexpected success reading stderr pipe")
}