Files
kata-containers/src/runtime/virtcontainers/monitor_test.go
bin liu bd8f03a5ef runtime: remove agent abstraction
This PR will delete agent abstraction and use Kata agent as the only one agent.

Fixes: #377

Signed-off-by: bin liu <bin@hyper.sh>
2020-07-08 10:07:40 +08:00

61 lines
1.3 KiB
Go

// Copyright (c) 2018 HyperHQ Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
package virtcontainers
import (
"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()
assert.Nil(err, "newWatcher failed: %v", err)
fakeErr := errors.New("foobar error")
m.notify(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()
assert.Nil(err, "newWatcher failed: %v", err)
close(ch)
fakeErr := errors.New("foobar error")
m.notify(fakeErr)
m.stop()
}