forked from kata-containers/kata-containers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor_test.go
61 lines (46 loc) · 1.43 KB
/
monitor_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
// Copyright (c) 2018 HyperHQ Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
package virtcontainers
import (
"context"
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMonitorSuccess(t *testing.T) {
contID := "505"
contConfig := newTestContainerConfigNoop(contID)
hConfig := newHypervisorConfig(nil, nil)
assert := assert.New(t)
// create a sandbox
s, err := testCreateSandbox(t, testSandboxID, MockHypervisor, hConfig, NetworkConfig{}, []ContainerConfig{contConfig}, nil)
assert.NoError(err)
defer cleanUp()
m := newMonitor(s)
ch, err := m.newWatcher(context.Background())
assert.Nil(err, "newWatcher failed: %v", err)
fakeErr := errors.New("foobar error")
m.notify(context.Background(), fakeErr)
resultErr := <-ch
assert.True(resultErr == fakeErr, "monitor notification mismatch %v vs. %v", resultErr, fakeErr)
m.stop()
}
func TestMonitorClosedChannel(t *testing.T) {
contID := "505"
contConfig := newTestContainerConfigNoop(contID)
hConfig := newHypervisorConfig(nil, nil)
assert := assert.New(t)
// create a sandbox
s, err := testCreateSandbox(t, testSandboxID, MockHypervisor, hConfig, NetworkConfig{}, []ContainerConfig{contConfig}, nil)
assert.NoError(err)
defer cleanUp()
m := newMonitor(s)
ch, err := m.newWatcher(context.Background())
assert.Nil(err, "newWatcher failed: %v", err)
close(ch)
fakeErr := errors.New("foobar error")
m.notify(context.Background(), fakeErr)
m.stop()
}