Add test flag for setting containerd address
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
89037568d3
commit
cebe099358
10
client.go
10
client.go
@ -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
|
// NewContainer will create a new container in container with the provided id
|
||||||
// the id must be unique within the namespace
|
// 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)
|
data, err := json.Marshal(spec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -170,7 +177,6 @@ func (c *Client) NewContainer(ctx context.Context, id string, image Image, spec
|
|||||||
TypeUrl: specs.Version,
|
TypeUrl: specs.Version,
|
||||||
Value: data,
|
Value: data,
|
||||||
},
|
},
|
||||||
Image: image.Name(),
|
|
||||||
}
|
}
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
if err := o(ctx, c, &container); err != nil {
|
if err := o(ctx, c, &container); err != nil {
|
||||||
|
@ -2,17 +2,22 @@ package containerd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"flag"
|
||||||
"testing"
|
"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) {
|
func TestNewClient(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip()
|
t.Skip()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
client, err := New(defaultAddress)
|
client, err := New(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -27,9 +32,8 @@ func TestNewClient(t *testing.T) {
|
|||||||
func TestImagePull(t *testing.T) {
|
func TestImagePull(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip()
|
t.Skip()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
client, err := New(defaultAddress)
|
client, err := New(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,8 @@ import (
|
|||||||
func TestContainerList(t *testing.T) {
|
func TestContainerList(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip()
|
t.Skip()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
client, err := New(defaultAddress)
|
client, err := New(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -29,9 +28,8 @@ func TestContainerList(t *testing.T) {
|
|||||||
func TestNewContainer(t *testing.T) {
|
func TestNewContainer(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip()
|
t.Skip()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
client, err := New(defaultAddress)
|
client, err := New(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
return func(s *specs.Spec) error {
|
||||||
var (
|
var (
|
||||||
image = i.(*image)
|
image = i.(*image)
|
||||||
|
@ -31,7 +31,7 @@ func createDefaultSpec() (*specs.Spec, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithImage(ctx context.Context, i Image) SpecOpts {
|
func WithImageConfig(ctx context.Context, i Image) SpecOpts {
|
||||||
return func(s *specs.Spec) error {
|
return func(s *specs.Spec) error {
|
||||||
var (
|
var (
|
||||||
image = i.(*image)
|
image = i.(*image)
|
||||||
|
16
task.go
16
task.go
@ -160,6 +160,16 @@ func (g *wgCloser) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TaskStatus string
|
||||||
|
|
||||||
|
const (
|
||||||
|
Running TaskStatus = "running"
|
||||||
|
Created TaskStatus = "created"
|
||||||
|
Stopped TaskStatus = "stopped"
|
||||||
|
Paused TaskStatus = "paused"
|
||||||
|
Pausing TaskStatus = "pausing"
|
||||||
|
)
|
||||||
|
|
||||||
type Task interface {
|
type Task interface {
|
||||||
Delete(context.Context) (uint32, error)
|
Delete(context.Context) (uint32, error)
|
||||||
Kill(context.Context, syscall.Signal) error
|
Kill(context.Context, syscall.Signal) error
|
||||||
@ -167,7 +177,7 @@ type Task interface {
|
|||||||
Resume(context.Context) error
|
Resume(context.Context) error
|
||||||
Pid() uint32
|
Pid() uint32
|
||||||
Start(context.Context) error
|
Start(context.Context) error
|
||||||
Status(context.Context) (string, error)
|
Status(context.Context) (TaskStatus, error)
|
||||||
Wait(context.Context) (uint32, error)
|
Wait(context.Context) (uint32, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,14 +228,14 @@ func (t *task) Resume(ctx context.Context) error {
|
|||||||
return err
|
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{
|
r, err := t.client.TaskService().Info(ctx, &execution.InfoRequest{
|
||||||
ContainerID: t.containerID,
|
ContainerID: t.containerID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
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
|
// Wait is a blocking call that will wait for the task to exit and return the exit status
|
||||||
|
Loading…
Reference in New Issue
Block a user