mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-16 23:17:42 +00:00
Modify calls in unit tests to use context since many functions were updated to accept local context to fix trace span ordering. Fixes #1355 Signed-off-by: Chelsea Mafrica <chelsea.e.mafrica@intel.com>
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
// 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()
|
|
}
|