Allow tests to specify their own events filter routine
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
parent
aa976325f5
commit
203651e774
2 changed files with 23 additions and 7 deletions
|
@ -102,6 +102,14 @@ func CreateBundleWithFilter(source, name string, args []string, filter func(spec
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetBundle(name string) *Bundle {
|
||||||
|
bundle, ok := bundleMap[name]
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &bundle
|
||||||
|
}
|
||||||
|
|
||||||
func CreateBusyboxBundle(name string, args []string) error {
|
func CreateBusyboxBundle(name string, args []string) error {
|
||||||
return CreateBundleWithFilter("busybox", name, args, nil)
|
return CreateBundleWithFilter("busybox", name, args, nil)
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,13 +180,13 @@ func NewContainerProcess(cs *ContainerdSuite, bundle *Bundle, cid, pid string) (
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cs *ContainerdSuite) StartContainer(id, bundleName string) (c *containerProcess, err error) {
|
func (cs *ContainerdSuite) StartContainerWithEventFilter(id, bundleName string, filter func(*types.Event)) (c *containerProcess, err error) {
|
||||||
bundle, ok := bundleMap[bundleName]
|
bundle := GetBundle(bundleName)
|
||||||
if !ok {
|
if bundle == nil {
|
||||||
return nil, fmt.Errorf("No such bundle '%s'", bundleName)
|
return nil, fmt.Errorf("No such bundle '%s'", bundleName)
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err = NewContainerProcess(cs, &bundle, id, "init")
|
c, err = NewContainerProcess(cs, bundle, id, "init")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -199,9 +199,13 @@ func (cs *ContainerdSuite) StartContainer(id, bundleName string) (c *containerPr
|
||||||
Stderr: filepath.Join(cs.cwd, c.io.stderr),
|
Stderr: filepath.Join(cs.cwd, c.io.stderr),
|
||||||
}
|
}
|
||||||
|
|
||||||
cs.SetContainerEventFilter(id, func(event *types.Event) {
|
if filter == nil {
|
||||||
|
filter = func(event *types.Event) {
|
||||||
c.eventsCh <- event
|
c.eventsCh <- event
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cs.SetContainerEventFilter(id, filter)
|
||||||
|
|
||||||
if _, err := cs.grpcClient.CreateContainer(context.Background(), r); err != nil {
|
if _, err := cs.grpcClient.CreateContainer(context.Background(), r); err != nil {
|
||||||
c.Cleanup()
|
c.Cleanup()
|
||||||
|
@ -211,6 +215,10 @@ func (cs *ContainerdSuite) StartContainer(id, bundleName string) (c *containerPr
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cs *ContainerdSuite) StartContainer(id, bundleName string) (c *containerProcess, err error) {
|
||||||
|
return cs.StartContainerWithEventFilter(id, bundleName, nil)
|
||||||
|
}
|
||||||
|
|
||||||
func (cs *ContainerdSuite) RunContainer(id, bundleName string) (c *containerProcess, err error) {
|
func (cs *ContainerdSuite) RunContainer(id, bundleName string) (c *containerProcess, err error) {
|
||||||
c, err = cs.StartContainer(id, bundleName)
|
c, err = cs.StartContainer(id, bundleName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue