Add test flag for setting containerd address

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2017-05-25 11:40:35 -07:00
parent 89037568d3
commit cebe099358
6 changed files with 34 additions and 16 deletions

View File

@ -156,9 +156,16 @@ func WithRuntime(name string) NewContainerOpts {
}
}
func WithImage(i Image) NewContainerOpts {
return func(ctx context.Context, client *Client, c *containers.Container) error {
c.Image = i.Name()
return nil
}
}
// NewContainer will create a new container in container with the provided id
// the id must be unique within the namespace
func (c *Client) NewContainer(ctx context.Context, id string, image Image, spec *specs.Spec, opts ...NewContainerOpts) (Container, error) {
func (c *Client) NewContainer(ctx context.Context, id string, spec *specs.Spec, opts ...NewContainerOpts) (Container, error) {
data, err := json.Marshal(spec)
if err != nil {
return nil, err
@ -170,7 +177,6 @@ func (c *Client) NewContainer(ctx context.Context, id string, image Image, spec
TypeUrl: specs.Version,
Value: data,
},
Image: image.Name(),
}
for _, o := range opts {
if err := o(ctx, c, &container); err != nil {

View File

@ -2,17 +2,22 @@ package containerd
import (
"context"
"flag"
"testing"
)
const defaultAddress = "/run/containerd/containerd.sock"
func init() {
flag.StringVar(&address, "address", "/run/containerd/containerd.sock", "The address to the containerd socket for use in the tests")
flag.Parse()
}
var address string
func TestNewClient(t *testing.T) {
if testing.Short() {
t.Skip()
return
}
client, err := New(defaultAddress)
client, err := New(address)
if err != nil {
t.Fatal(err)
}
@ -27,9 +32,8 @@ func TestNewClient(t *testing.T) {
func TestImagePull(t *testing.T) {
if testing.Short() {
t.Skip()
return
}
client, err := New(defaultAddress)
client, err := New(address)
if err != nil {
t.Fatal(err)
}

View File

@ -8,9 +8,8 @@ import (
func TestContainerList(t *testing.T) {
if testing.Short() {
t.Skip()
return
}
client, err := New(defaultAddress)
client, err := New(address)
if err != nil {
t.Fatal(err)
}
@ -29,9 +28,8 @@ func TestContainerList(t *testing.T) {
func TestNewContainer(t *testing.T) {
if testing.Short() {
t.Skip()
return
}
client, err := New(defaultAddress)
client, err := New(address)
if err != nil {
t.Fatal(err)
}

View File

@ -183,7 +183,7 @@ func WithHostNamespace(ns specs.LinuxNamespaceType) SpecOpts {
}
}
func WithImage(ctx context.Context, i Image) SpecOpts {
func WithImageConfig(ctx context.Context, i Image) SpecOpts {
return func(s *specs.Spec) error {
var (
image = i.(*image)

View File

@ -31,7 +31,7 @@ func createDefaultSpec() (*specs.Spec, error) {
}, nil
}
func WithImage(ctx context.Context, i Image) SpecOpts {
func WithImageConfig(ctx context.Context, i Image) SpecOpts {
return func(s *specs.Spec) error {
var (
image = i.(*image)

16
task.go
View File

@ -160,6 +160,16 @@ func (g *wgCloser) Close() error {
return nil
}
type TaskStatus string
const (
Running TaskStatus = "running"
Created TaskStatus = "created"
Stopped TaskStatus = "stopped"
Paused TaskStatus = "paused"
Pausing TaskStatus = "pausing"
)
type Task interface {
Delete(context.Context) (uint32, error)
Kill(context.Context, syscall.Signal) error
@ -167,7 +177,7 @@ type Task interface {
Resume(context.Context) error
Pid() uint32
Start(context.Context) error
Status(context.Context) (string, error)
Status(context.Context) (TaskStatus, error)
Wait(context.Context) (uint32, error)
}
@ -218,14 +228,14 @@ func (t *task) Resume(ctx context.Context) error {
return err
}
func (t *task) Status(ctx context.Context) (string, error) {
func (t *task) Status(ctx context.Context) (TaskStatus, error) {
r, err := t.client.TaskService().Info(ctx, &execution.InfoRequest{
ContainerID: t.containerID,
})
if err != nil {
return "", err
}
return r.Task.Status.String(), nil
return TaskStatus(r.Task.Status.String()), nil
}
// Wait is a blocking call that will wait for the task to exit and return the exit status