forked from kata-containers/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iostream_test.go
57 lines (43 loc) · 1.34 KB
/
iostream_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
// Copyright (c) 2018 HyperHQ Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
package virtcontainers
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIOStream(t *testing.T) {
hConfig := newHypervisorConfig(nil, nil)
s, err := testCreateSandbox(t, testSandboxID, MockHypervisor, hConfig, NoopAgentType, NetworkConfig{}, []ContainerConfig{}, nil)
assert.NoError(t, err)
defer cleanUp()
contID := "foo"
processID := "bar"
config := newTestContainerConfigNoop(contID)
c := &Container{
sandbox: s,
config: &config,
}
stream := newIOStream(s, c, processID)
stdin := stream.stdin()
stdout := stream.stdout()
stderr := stream.stderr()
buffer := []byte("randombufferdata")
_, err = stdin.Write(buffer)
assert.Nil(t, err, "stdin write failed: %s", err)
_, err = stdout.Read(buffer)
assert.Nil(t, err, "stdout read failed: %s", err)
_, err = stderr.Read(buffer)
assert.Nil(t, err, "stderr read failed: %s", err)
err = stdin.Close()
assert.Nil(t, err, "stream close failed: %s", err)
_, err = stdin.Write(buffer)
assert.NotNil(t, err, "stdin write closed should fail")
_, err = stdout.Read(buffer)
assert.NotNil(t, err, "stdout read closed should fail")
_, err = stderr.Read(buffer)
assert.NotNil(t, err, "stderr read closed should fail")
err = stdin.Close()
assert.NotNil(t, err, "stdin close closed should fail")
}