Fix TestContainerNoBinaryExists on windows

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
Kenfe-Mickael Laventure 2017-08-11 11:57:00 -07:00
parent 104a8088ca
commit b02e9a844e
No known key found for this signature in database
GPG Key ID: 40CF16616B361216
3 changed files with 15 additions and 5 deletions

View File

@ -805,7 +805,7 @@ func TestContainerNoBinaryExists(t *testing.T) {
}
}
spec, err := generateSpec(withImageConfig(ctx, image), withProcessArgs("nothing"))
spec, err := generateSpec(withImageConfig(ctx, image), WithProcessArgs("nothing"))
if err != nil {
t.Error(err)
return
@ -821,11 +821,12 @@ func TestContainerNoBinaryExists(t *testing.T) {
switch runtime.GOOS {
case "windows":
if err != nil {
t.Errorf("failed to create task %v", err)
t.Fatalf("failed to create task %v", err)
}
if err := task.Start(ctx); err != nil {
defer task.Delete(ctx)
if err := task.Start(ctx); err == nil {
task.Kill(ctx, syscall.SIGKILL)
t.Error("task.Start() should return an error when binary does not exist")
task.Delete(ctx)
}
default:
if err == nil {

10
task.go
View File

@ -17,6 +17,7 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/rootfs"
"github.com/containerd/containerd/runtime"
"github.com/containerd/containerd/typeurl"
@ -117,7 +118,8 @@ type Task interface {
var _ = (Task)(&task{})
type task struct {
client *Client
client *Client
container Container
io *IO
id string
@ -250,6 +252,12 @@ func (t *task) Delete(ctx context.Context, opts ...ProcessDeleteOpts) (uint32, e
}
switch status.Status {
case Stopped, Unknown, "":
case Created:
if t.client.runtime == fmt.Sprintf("%s.%s", plugin.RuntimePlugin, "windows") {
// On windows Created is akin to Stopped
break
}
fallthrough
default:
return UnknownExitStatus, errors.Wrapf(errdefs.ErrFailedPrecondition, "task must be stopped before deletion: %s", status.Status)
}

View File

@ -114,6 +114,7 @@ func (t *task) Start(ctx context.Context) error {
return err
}
if err := p.Start(ctx); err != nil {
t.removeProcess(t.id)
return err
}
t.publisher.Publish(ctx,