Cleanup extra returns in tests
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
parent
cee56a1226
commit
1cd32fa68d
@ -184,7 +184,6 @@ func TestImagePull(t *testing.T) {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
_, err = client.Pull(ctx, testImage)
|
_, err = client.Pull(ctx, testImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,66 +27,55 @@ func TestCheckpointRestore(t *testing.T) {
|
|||||||
|
|
||||||
image, err := client.GetImage(ctx, testImage)
|
image, err := client.GetImage(ctx, testImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
container, err := client.NewContainer(ctx, id, WithNewSpec(oci.WithImageConfig(image), oci.WithProcessArgs("sleep", "100")), WithNewSnapshot(id, image))
|
container, err := client.NewContainer(ctx, id, WithNewSpec(oci.WithImageConfig(image), oci.WithProcessArgs("sleep", "100")), WithNewSnapshot(id, image))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer container.Delete(ctx, WithSnapshotCleanup)
|
defer container.Delete(ctx, WithSnapshotCleanup)
|
||||||
|
|
||||||
task, err := container.NewTask(ctx, empty())
|
task, err := container.NewTask(ctx, empty())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer task.Delete(ctx)
|
defer task.Delete(ctx)
|
||||||
|
|
||||||
statusC, err := task.Wait(ctx)
|
statusC, err := task.Wait(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := task.Start(ctx); err != nil {
|
if err := task.Start(ctx); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkpoint, err := task.Checkpoint(ctx, WithExit)
|
checkpoint, err := task.Checkpoint(ctx, WithExit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<-statusC
|
<-statusC
|
||||||
|
|
||||||
if _, err := task.Delete(ctx); err != nil {
|
if _, err := task.Delete(ctx); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if task, err = container.NewTask(ctx, empty(), WithTaskCheckpoint(checkpoint)); err != nil {
|
if task, err = container.NewTask(ctx, empty(), WithTaskCheckpoint(checkpoint)); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer task.Delete(ctx)
|
defer task.Delete(ctx)
|
||||||
|
|
||||||
statusC, err = task.Wait(ctx)
|
statusC, err = task.Wait(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := task.Start(ctx); err != nil {
|
if err := task.Start(ctx); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
|
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
<-statusC
|
<-statusC
|
||||||
}
|
}
|
||||||
@ -107,74 +96,61 @@ func TestCheckpointRestoreNewContainer(t *testing.T) {
|
|||||||
|
|
||||||
image, err := client.GetImage(ctx, testImage)
|
image, err := client.GetImage(ctx, testImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
container, err := client.NewContainer(ctx, id, WithNewSpec(oci.WithImageConfig(image), oci.WithProcessArgs("sleep", "100")), WithNewSnapshot(id, image))
|
container, err := client.NewContainer(ctx, id, WithNewSpec(oci.WithImageConfig(image), oci.WithProcessArgs("sleep", "100")), WithNewSnapshot(id, image))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer container.Delete(ctx, WithSnapshotCleanup)
|
defer container.Delete(ctx, WithSnapshotCleanup)
|
||||||
|
|
||||||
task, err := container.NewTask(ctx, empty())
|
task, err := container.NewTask(ctx, empty())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer task.Delete(ctx)
|
defer task.Delete(ctx)
|
||||||
|
|
||||||
statusC, err := task.Wait(ctx)
|
statusC, err := task.Wait(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := task.Start(ctx); err != nil {
|
if err := task.Start(ctx); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkpoint, err := task.Checkpoint(ctx, WithExit)
|
checkpoint, err := task.Checkpoint(ctx, WithExit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<-statusC
|
<-statusC
|
||||||
|
|
||||||
if _, err := task.Delete(ctx); err != nil {
|
if _, err := task.Delete(ctx); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if err := container.Delete(ctx, WithSnapshotCleanup); err != nil {
|
if err := container.Delete(ctx, WithSnapshotCleanup); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if container, err = client.NewContainer(ctx, id, WithCheckpoint(checkpoint, id)); err != nil {
|
if container, err = client.NewContainer(ctx, id, WithCheckpoint(checkpoint, id)); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if task, err = container.NewTask(ctx, empty(), WithTaskCheckpoint(checkpoint)); err != nil {
|
if task, err = container.NewTask(ctx, empty(), WithTaskCheckpoint(checkpoint)); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer task.Delete(ctx)
|
defer task.Delete(ctx)
|
||||||
|
|
||||||
statusC, err = task.Wait(ctx)
|
statusC, err = task.Wait(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := task.Start(ctx); err != nil {
|
if err := task.Start(ctx); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
|
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
<-statusC
|
<-statusC
|
||||||
}
|
}
|
||||||
@ -200,52 +176,43 @@ func TestCheckpointLeaveRunning(t *testing.T) {
|
|||||||
|
|
||||||
image, err := client.GetImage(ctx, testImage)
|
image, err := client.GetImage(ctx, testImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
container, err := client.NewContainer(ctx, id, WithNewSpec(oci.WithImageConfig(image), oci.WithProcessArgs("sleep", "100")), WithNewSnapshot(id, image))
|
container, err := client.NewContainer(ctx, id, WithNewSpec(oci.WithImageConfig(image), oci.WithProcessArgs("sleep", "100")), WithNewSnapshot(id, image))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer container.Delete(ctx, WithSnapshotCleanup)
|
defer container.Delete(ctx, WithSnapshotCleanup)
|
||||||
|
|
||||||
task, err := container.NewTask(ctx, empty())
|
task, err := container.NewTask(ctx, empty())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer task.Delete(ctx)
|
defer task.Delete(ctx)
|
||||||
|
|
||||||
statusC, err := task.Wait(ctx)
|
statusC, err := task.Wait(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := task.Start(ctx); err != nil {
|
if err := task.Start(ctx); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := task.Checkpoint(ctx); err != nil {
|
if _, err := task.Checkpoint(ctx); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
status, err := task.Status(ctx)
|
status, err := task.Status(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if status.Status != Running {
|
if status.Status != Running {
|
||||||
t.Errorf("expected status %q but received %q", Running, status)
|
t.Fatalf("expected status %q but received %q", Running, status)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
|
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<-statusC
|
<-statusC
|
||||||
|
@ -43,8 +43,7 @@ func TestTaskUpdate(t *testing.T) {
|
|||||||
|
|
||||||
image, err := client.GetImage(ctx, testImage)
|
image, err := client.GetImage(ctx, testImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
limit := int64(32 * 1024 * 1024)
|
limit := int64(32 * 1024 * 1024)
|
||||||
memory := func(_ context.Context, _ oci.Client, _ *containers.Container, s *specs.Spec) error {
|
memory := func(_ context.Context, _ oci.Client, _ *containers.Container, s *specs.Spec) error {
|
||||||
@ -57,38 +56,32 @@ func TestTaskUpdate(t *testing.T) {
|
|||||||
WithNewSpec(oci.WithImageConfig(image), withProcessArgs("sleep", "30"), memory),
|
WithNewSpec(oci.WithImageConfig(image), withProcessArgs("sleep", "30"), memory),
|
||||||
WithNewSnapshot(id, image))
|
WithNewSnapshot(id, image))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer container.Delete(ctx, WithSnapshotCleanup)
|
defer container.Delete(ctx, WithSnapshotCleanup)
|
||||||
|
|
||||||
task, err := container.NewTask(ctx, empty())
|
task, err := container.NewTask(ctx, empty())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer task.Delete(ctx)
|
defer task.Delete(ctx)
|
||||||
|
|
||||||
statusC, err := task.Wait(ctx)
|
statusC, err := task.Wait(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check that the task has a limit of 32mb
|
// check that the task has a limit of 32mb
|
||||||
cgroup, err := cgroups.Load(cgroups.V1, cgroups.PidPath(int(task.Pid())))
|
cgroup, err := cgroups.Load(cgroups.V1, cgroups.PidPath(int(task.Pid())))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
stat, err := cgroup.Stat(cgroups.IgnoreNotExist)
|
stat, err := cgroup.Stat(cgroups.IgnoreNotExist)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if int64(stat.Memory.Usage.Limit) != limit {
|
if int64(stat.Memory.Usage.Limit) != limit {
|
||||||
t.Errorf("expected memory limit to be set to %d but received %d", limit, stat.Memory.Usage.Limit)
|
t.Fatalf("expected memory limit to be set to %d but received %d", limit, stat.Memory.Usage.Limit)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
limit = 64 * 1024 * 1024
|
limit = 64 * 1024 * 1024
|
||||||
if err := task.Update(ctx, WithResources(&specs.LinuxResources{
|
if err := task.Update(ctx, WithResources(&specs.LinuxResources{
|
||||||
@ -100,15 +93,13 @@ func TestTaskUpdate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
// check that the task has a limit of 64mb
|
// check that the task has a limit of 64mb
|
||||||
if stat, err = cgroup.Stat(cgroups.IgnoreNotExist); err != nil {
|
if stat, err = cgroup.Stat(cgroups.IgnoreNotExist); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if int64(stat.Memory.Usage.Limit) != limit {
|
if int64(stat.Memory.Usage.Limit) != limit {
|
||||||
t.Errorf("expected memory limit to be set to %d but received %d", limit, stat.Memory.Usage.Limit)
|
t.Errorf("expected memory limit to be set to %d but received %d", limit, stat.Memory.Usage.Limit)
|
||||||
}
|
}
|
||||||
if err := task.Kill(ctx, unix.SIGKILL); err != nil {
|
if err := task.Kill(ctx, unix.SIGKILL); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<-statusC
|
<-statusC
|
||||||
@ -131,21 +122,18 @@ func TestShimInCgroup(t *testing.T) {
|
|||||||
|
|
||||||
image, err := client.GetImage(ctx, testImage)
|
image, err := client.GetImage(ctx, testImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
container, err := client.NewContainer(ctx, id, WithNewSpec(oci.WithImageConfig(image), oci.WithProcessArgs("sleep", "30")), WithNewSnapshot(id, image))
|
container, err := client.NewContainer(ctx, id, WithNewSpec(oci.WithImageConfig(image), oci.WithProcessArgs("sleep", "30")), WithNewSnapshot(id, image))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer container.Delete(ctx, WithSnapshotCleanup)
|
defer container.Delete(ctx, WithSnapshotCleanup)
|
||||||
// create a cgroup for the shim to use
|
// create a cgroup for the shim to use
|
||||||
path := "/containerd/shim"
|
path := "/containerd/shim"
|
||||||
cg, err := cgroups.New(cgroups.V1, cgroups.StaticPath(path), &specs.LinuxResources{})
|
cg, err := cgroups.New(cgroups.V1, cgroups.StaticPath(path), &specs.LinuxResources{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer cg.Delete()
|
defer cg.Delete()
|
||||||
|
|
||||||
@ -156,29 +144,25 @@ func TestShimInCgroup(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer task.Delete(ctx)
|
defer task.Delete(ctx)
|
||||||
|
|
||||||
statusC, err := task.Wait(ctx)
|
statusC, err := task.Wait(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check to see if the shim is inside the cgroup
|
// check to see if the shim is inside the cgroup
|
||||||
processes, err := cg.Processes(cgroups.Devices, false)
|
processes, err := cg.Processes(cgroups.Devices, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if len(processes) == 0 {
|
if len(processes) == 0 {
|
||||||
t.Errorf("created cgroup should have atleast one process inside: %d", len(processes))
|
t.Errorf("created cgroup should have atleast one process inside: %d", len(processes))
|
||||||
}
|
}
|
||||||
if err := task.Kill(ctx, unix.SIGKILL); err != nil {
|
if err := task.Kill(ctx, unix.SIGKILL); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<-statusC
|
<-statusC
|
||||||
@ -200,33 +184,28 @@ func TestDaemonRestart(t *testing.T) {
|
|||||||
|
|
||||||
image, err = client.GetImage(ctx, testImage)
|
image, err = client.GetImage(ctx, testImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
container, err := client.NewContainer(ctx, id, WithNewSpec(withImageConfig(image), withProcessArgs("sleep", "30")), withNewSnapshot(id, image))
|
container, err := client.NewContainer(ctx, id, WithNewSpec(withImageConfig(image), withProcessArgs("sleep", "30")), withNewSnapshot(id, image))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer container.Delete(ctx, WithSnapshotCleanup)
|
defer container.Delete(ctx, WithSnapshotCleanup)
|
||||||
|
|
||||||
task, err := container.NewTask(ctx, empty())
|
task, err := container.NewTask(ctx, empty())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer task.Delete(ctx)
|
defer task.Delete(ctx)
|
||||||
|
|
||||||
statusC, err := task.Wait(ctx)
|
statusC, err := task.Wait(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := task.Start(ctx); err != nil {
|
if err := task.Start(ctx); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var exitStatus ExitStatus
|
var exitStatus ExitStatus
|
||||||
@ -249,8 +228,7 @@ func TestDaemonRestart(t *testing.T) {
|
|||||||
|
|
||||||
statusC, err = task.Wait(ctx)
|
statusC, err = task.Wait(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
|
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
|
||||||
@ -285,14 +263,12 @@ func TestContainerAttach(t *testing.T) {
|
|||||||
|
|
||||||
image, err = client.GetImage(ctx, testImage)
|
image, err = client.GetImage(ctx, testImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
container, err := client.NewContainer(ctx, id, WithNewSpec(withImageConfig(image), withCat()), withNewSnapshot(id, image))
|
container, err := client.NewContainer(ctx, id, WithNewSpec(withImageConfig(image), withCat()), withNewSnapshot(id, image))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer container.Delete(ctx, WithSnapshotCleanup)
|
defer container.Delete(ctx, WithSnapshotCleanup)
|
||||||
|
|
||||||
@ -300,8 +276,7 @@ func TestContainerAttach(t *testing.T) {
|
|||||||
|
|
||||||
direct, err := newDirectIO(ctx)
|
direct, err := newDirectIO(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer direct.Delete()
|
defer direct.Delete()
|
||||||
var (
|
var (
|
||||||
@ -316,8 +291,7 @@ func TestContainerAttach(t *testing.T) {
|
|||||||
|
|
||||||
task, err := container.NewTask(ctx, direct.IOCreate)
|
task, err := container.NewTask(ctx, direct.IOCreate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer task.Delete(ctx)
|
defer task.Delete(ctx)
|
||||||
|
|
||||||
@ -327,8 +301,7 @@ func TestContainerAttach(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := task.Start(ctx); err != nil {
|
if err := task.Start(ctx); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := fmt.Fprint(direct.Stdin, expected); err != nil {
|
if _, err := fmt.Fprint(direct.Stdin, expected); err != nil {
|
||||||
@ -337,13 +310,11 @@ func TestContainerAttach(t *testing.T) {
|
|||||||
|
|
||||||
// load the container and re-load the task
|
// load the container and re-load the task
|
||||||
if container, err = client.LoadContainer(ctx, id); err != nil {
|
if container, err = client.LoadContainer(ctx, id); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if task, err = container.Task(ctx, direct.IOAttach); err != nil {
|
if task, err = container.Task(ctx, direct.IOAttach); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := fmt.Fprint(direct.Stdin, expected); err != nil {
|
if _, err := fmt.Fprint(direct.Stdin, expected); err != nil {
|
||||||
@ -437,13 +408,11 @@ func TestContainerUsername(t *testing.T) {
|
|||||||
|
|
||||||
image, err = client.GetImage(ctx, testImage)
|
image, err = client.GetImage(ctx, testImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
direct, err := newDirectIO(ctx)
|
direct, err := newDirectIO(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer direct.Delete()
|
defer direct.Delete()
|
||||||
var (
|
var (
|
||||||
@ -462,27 +431,23 @@ func TestContainerUsername(t *testing.T) {
|
|||||||
WithNewSpec(withImageConfig(image), oci.WithUsername("squid"), oci.WithProcessArgs("id", "-u")),
|
WithNewSpec(withImageConfig(image), oci.WithUsername("squid"), oci.WithProcessArgs("id", "-u")),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer container.Delete(ctx, WithSnapshotCleanup)
|
defer container.Delete(ctx, WithSnapshotCleanup)
|
||||||
|
|
||||||
task, err := container.NewTask(ctx, direct.IOCreate)
|
task, err := container.NewTask(ctx, direct.IOCreate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer task.Delete(ctx)
|
defer task.Delete(ctx)
|
||||||
|
|
||||||
statusC, err := task.Wait(ctx)
|
statusC, err := task.Wait(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := task.Start(ctx); err != nil {
|
if err := task.Start(ctx); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
<-statusC
|
<-statusC
|
||||||
|
|
||||||
@ -519,14 +484,12 @@ func TestContainerAttachProcess(t *testing.T) {
|
|||||||
|
|
||||||
image, err = client.GetImage(ctx, testImage)
|
image, err = client.GetImage(ctx, testImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
container, err := client.NewContainer(ctx, id, WithNewSpec(withImageConfig(image), withProcessArgs("sleep", "100")), withNewSnapshot(id, image))
|
container, err := client.NewContainer(ctx, id, WithNewSpec(withImageConfig(image), withProcessArgs("sleep", "100")), withNewSnapshot(id, image))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer container.Delete(ctx, WithSnapshotCleanup)
|
defer container.Delete(ctx, WithSnapshotCleanup)
|
||||||
|
|
||||||
@ -535,8 +498,7 @@ func TestContainerAttachProcess(t *testing.T) {
|
|||||||
// creating IO early for easy resource cleanup
|
// creating IO early for easy resource cleanup
|
||||||
direct, err := newDirectIO(ctx)
|
direct, err := newDirectIO(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer direct.Delete()
|
defer direct.Delete()
|
||||||
var (
|
var (
|
||||||
@ -551,8 +513,7 @@ func TestContainerAttachProcess(t *testing.T) {
|
|||||||
|
|
||||||
task, err := container.NewTask(ctx, empty())
|
task, err := container.NewTask(ctx, empty())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer task.Delete(ctx)
|
defer task.Delete(ctx)
|
||||||
|
|
||||||
@ -562,14 +523,12 @@ func TestContainerAttachProcess(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := task.Start(ctx); err != nil {
|
if err := task.Start(ctx); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spec, err := container.Spec(ctx)
|
spec, err := container.Spec(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
processSpec := spec.Process
|
processSpec := spec.Process
|
||||||
@ -577,18 +536,15 @@ func TestContainerAttachProcess(t *testing.T) {
|
|||||||
execID := t.Name() + "_exec"
|
execID := t.Name() + "_exec"
|
||||||
process, err := task.Exec(ctx, execID, processSpec, direct.IOCreate)
|
process, err := task.Exec(ctx, execID, processSpec, direct.IOCreate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
processStatusC, err := process.Wait(ctx)
|
processStatusC, err := process.Wait(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := process.Start(ctx); err != nil {
|
if err := process.Start(ctx); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := fmt.Fprint(direct.Stdin, expected); err != nil {
|
if _, err := fmt.Fprint(direct.Stdin, expected); err != nil {
|
||||||
@ -596,8 +552,7 @@ func TestContainerAttachProcess(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if process, err = task.LoadProcess(ctx, execID, direct.IOAttach); err != nil {
|
if process, err = task.LoadProcess(ctx, execID, direct.IOAttach); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := fmt.Fprint(direct.Stdin, expected); err != nil {
|
if _, err := fmt.Fprint(direct.Stdin, expected); err != nil {
|
||||||
@ -646,13 +601,11 @@ func TestContainerUserID(t *testing.T) {
|
|||||||
|
|
||||||
image, err = client.GetImage(ctx, testImage)
|
image, err = client.GetImage(ctx, testImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
direct, err := newDirectIO(ctx)
|
direct, err := newDirectIO(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer direct.Delete()
|
defer direct.Delete()
|
||||||
var (
|
var (
|
||||||
@ -671,27 +624,23 @@ func TestContainerUserID(t *testing.T) {
|
|||||||
WithNewSpec(withImageConfig(image), oci.WithUserID(3), oci.WithProcessArgs("sh", "-c", "echo $(id -u):$(id -g)")),
|
WithNewSpec(withImageConfig(image), oci.WithUserID(3), oci.WithProcessArgs("sh", "-c", "echo $(id -u):$(id -g)")),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer container.Delete(ctx, WithSnapshotCleanup)
|
defer container.Delete(ctx, WithSnapshotCleanup)
|
||||||
|
|
||||||
task, err := container.NewTask(ctx, direct.IOCreate)
|
task, err := container.NewTask(ctx, direct.IOCreate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer task.Delete(ctx)
|
defer task.Delete(ctx)
|
||||||
|
|
||||||
statusC, err := task.Wait(ctx)
|
statusC, err := task.Wait(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := task.Start(ctx); err != nil {
|
if err := task.Start(ctx); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
<-statusC
|
<-statusC
|
||||||
|
|
||||||
@ -721,8 +670,7 @@ func TestContainerKillAll(t *testing.T) {
|
|||||||
|
|
||||||
image, err = client.GetImage(ctx, testImage)
|
image, err = client.GetImage(ctx, testImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
container, err := client.NewContainer(ctx, id,
|
container, err := client.NewContainer(ctx, id,
|
||||||
@ -733,28 +681,24 @@ func TestContainerKillAll(t *testing.T) {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer container.Delete(ctx, WithSnapshotCleanup)
|
defer container.Delete(ctx, WithSnapshotCleanup)
|
||||||
|
|
||||||
stdout := bytes.NewBuffer(nil)
|
stdout := bytes.NewBuffer(nil)
|
||||||
task, err := container.NewTask(ctx, cio.NewCreator(withByteBuffers(stdout)))
|
task, err := container.NewTask(ctx, cio.NewCreator(withByteBuffers(stdout)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer task.Delete(ctx)
|
defer task.Delete(ctx)
|
||||||
|
|
||||||
statusC, err := task.Wait(ctx)
|
statusC, err := task.Wait(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := task.Start(ctx); err != nil {
|
if err := task.Start(ctx); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := task.Kill(ctx, syscall.SIGKILL, WithKillAll); err != nil {
|
if err := task.Kill(ctx, syscall.SIGKILL, WithKillAll); err != nil {
|
||||||
@ -763,8 +707,7 @@ func TestContainerKillAll(t *testing.T) {
|
|||||||
|
|
||||||
<-statusC
|
<-statusC
|
||||||
if _, err := task.Delete(ctx); err != nil {
|
if _, err := task.Delete(ctx); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -848,8 +791,7 @@ func TestDaemonRestartWithRunningShim(t *testing.T) {
|
|||||||
|
|
||||||
image, err = client.GetImage(ctx, testImage)
|
image, err = client.GetImage(ctx, testImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
container, err := client.NewContainer(ctx, id, WithNewSpec(oci.WithImageConfig(image), oci.WithProcessArgs("sleep", "100")), withNewSnapshot(id, image))
|
container, err := client.NewContainer(ctx, id, WithNewSpec(oci.WithImageConfig(image), oci.WithProcessArgs("sleep", "100")), withNewSnapshot(id, image))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -930,8 +872,7 @@ func TestContainerRuntimeOptions(t *testing.T) {
|
|||||||
|
|
||||||
image, err = client.GetImage(ctx, testImage)
|
image, err = client.GetImage(ctx, testImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
container, err := client.NewContainer(
|
container, err := client.NewContainer(
|
||||||
@ -941,8 +882,7 @@ func TestContainerRuntimeOptions(t *testing.T) {
|
|||||||
WithRuntime("io.containerd.runtime.v1.linux", &runctypes.RuncOptions{Runtime: "no-runc"}),
|
WithRuntime("io.containerd.runtime.v1.linux", &runctypes.RuncOptions{Runtime: "no-runc"}),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer container.Delete(ctx, WithSnapshotCleanup)
|
defer container.Delete(ctx, WithSnapshotCleanup)
|
||||||
|
|
||||||
@ -973,8 +913,7 @@ func TestContainerKillInitPidHost(t *testing.T) {
|
|||||||
|
|
||||||
image, err = client.GetImage(ctx, testImage)
|
image, err = client.GetImage(ctx, testImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
container, err := client.NewContainer(ctx, id,
|
container, err := client.NewContainer(ctx, id,
|
||||||
@ -985,28 +924,24 @@ func TestContainerKillInitPidHost(t *testing.T) {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer container.Delete(ctx, WithSnapshotCleanup)
|
defer container.Delete(ctx, WithSnapshotCleanup)
|
||||||
|
|
||||||
stdout := bytes.NewBuffer(nil)
|
stdout := bytes.NewBuffer(nil)
|
||||||
task, err := container.NewTask(ctx, cio.NewCreator(withByteBuffers(stdout)))
|
task, err := container.NewTask(ctx, cio.NewCreator(withByteBuffers(stdout)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer task.Delete(ctx)
|
defer task.Delete(ctx)
|
||||||
|
|
||||||
statusC, err := task.Wait(ctx)
|
statusC, err := task.Wait(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := task.Start(ctx); err != nil {
|
if err := task.Start(ctx); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
|
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
|
||||||
@ -1069,8 +1004,7 @@ func testUserNamespaces(t *testing.T, readonlyRootFS bool) {
|
|||||||
|
|
||||||
image, err = client.GetImage(ctx, testImage)
|
image, err = client.GetImage(ctx, testImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := []NewContainerOpts{WithNewSpec(withImageConfig(image),
|
opts := []NewContainerOpts{WithNewSpec(withImageConfig(image),
|
||||||
@ -1085,8 +1019,7 @@ func testUserNamespaces(t *testing.T, readonlyRootFS bool) {
|
|||||||
|
|
||||||
container, err := client.NewContainer(ctx, id, opts...)
|
container, err := client.NewContainer(ctx, id, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer container.Delete(ctx, WithSnapshotCleanup)
|
defer container.Delete(ctx, WithSnapshotCleanup)
|
||||||
|
|
||||||
@ -1098,15 +1031,13 @@ func testUserNamespaces(t *testing.T, readonlyRootFS bool) {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer task.Delete(ctx)
|
defer task.Delete(ctx)
|
||||||
|
|
||||||
statusC, err := task.Wait(ctx)
|
statusC, err := task.Wait(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if pid := task.Pid(); pid <= 0 {
|
if pid := task.Pid(); pid <= 0 {
|
||||||
@ -1120,16 +1051,14 @@ func testUserNamespaces(t *testing.T, readonlyRootFS bool) {
|
|||||||
status := <-statusC
|
status := <-statusC
|
||||||
code, _, err := status.Result()
|
code, _, err := status.Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if code != 7 {
|
if code != 7 {
|
||||||
t.Errorf("expected status 7 from wait but received %d", code)
|
t.Errorf("expected status 7 from wait but received %d", code)
|
||||||
}
|
}
|
||||||
deleteStatus, err := task.Delete(ctx)
|
deleteStatus, err := task.Delete(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if ec := deleteStatus.ExitCode(); ec != 7 {
|
if ec := deleteStatus.ExitCode(); ec != 7 {
|
||||||
t.Errorf("expected status 7 from delete but received %d", ec)
|
t.Errorf("expected status 7 from delete but received %d", ec)
|
||||||
@ -1155,32 +1084,27 @@ func TestTaskResize(t *testing.T) {
|
|||||||
if runtime.GOOS != "windows" {
|
if runtime.GOOS != "windows" {
|
||||||
image, err = client.GetImage(ctx, testImage)
|
image, err = client.GetImage(ctx, testImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
container, err := client.NewContainer(ctx, id, WithNewSpec(withImageConfig(image), withExitStatus(7)), withNewSnapshot(id, image))
|
container, err := client.NewContainer(ctx, id, WithNewSpec(withImageConfig(image), withExitStatus(7)), withNewSnapshot(id, image))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer container.Delete(ctx, WithSnapshotCleanup)
|
defer container.Delete(ctx, WithSnapshotCleanup)
|
||||||
|
|
||||||
task, err := container.NewTask(ctx, empty())
|
task, err := container.NewTask(ctx, empty())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer task.Delete(ctx)
|
defer task.Delete(ctx)
|
||||||
|
|
||||||
statusC, err := task.Wait(ctx)
|
statusC, err := task.Wait(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if err := task.Resize(ctx, 32, 32); err != nil {
|
if err := task.Resize(ctx, 32, 32); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
task.Kill(ctx, syscall.SIGKILL)
|
task.Kill(ctx, syscall.SIGKILL)
|
||||||
<-statusC
|
<-statusC
|
||||||
@ -1201,14 +1125,12 @@ func TestContainerImage(t *testing.T) {
|
|||||||
|
|
||||||
image, err := client.GetImage(ctx, testImage)
|
image, err := client.GetImage(ctx, testImage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
container, err := client.NewContainer(ctx, id, WithNewSpec(), WithImage(image))
|
container, err := client.NewContainer(ctx, id, WithNewSpec(), WithImage(image))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer container.Delete(ctx)
|
defer container.Delete(ctx)
|
||||||
|
|
||||||
@ -1236,8 +1158,7 @@ func TestContainerNoImage(t *testing.T) {
|
|||||||
|
|
||||||
container, err := client.NewContainer(ctx, id, WithNewSpec())
|
container, err := client.NewContainer(ctx, id, WithNewSpec())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer container.Delete(ctx)
|
defer container.Delete(ctx)
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -316,8 +316,7 @@ func checkNodesEqual(t *testing.T, n1, n2 []gc.Node) {
|
|||||||
sort.Sort(nodeList(n2))
|
sort.Sort(nodeList(n2))
|
||||||
|
|
||||||
if len(n1) != len(n2) {
|
if len(n1) != len(n2) {
|
||||||
t.Errorf("Nodes do not match\n\tExpected:\n\t%v\n\tActual:\n\t%v", n2, n1)
|
t.Fatalf("Nodes do not match\n\tExpected:\n\t%v\n\tActual:\n\t%v", n2, n1)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range n1 {
|
for i := range n1 {
|
||||||
|
@ -41,13 +41,11 @@ func TestOverlayMounts(t *testing.T) {
|
|||||||
defer os.RemoveAll(root)
|
defer os.RemoveAll(root)
|
||||||
o, _, err := newSnapshotter(ctx, root)
|
o, _, err := newSnapshotter(ctx, root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
mounts, err := o.Prepare(ctx, "/tmp/test", "")
|
mounts, err := o.Prepare(ctx, "/tmp/test", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if len(mounts) != 1 {
|
if len(mounts) != 1 {
|
||||||
t.Errorf("should only have 1 mount but received %d", len(mounts))
|
t.Errorf("should only have 1 mount but received %d", len(mounts))
|
||||||
@ -77,23 +75,19 @@ func TestOverlayCommit(t *testing.T) {
|
|||||||
defer os.RemoveAll(root)
|
defer os.RemoveAll(root)
|
||||||
o, _, err := newSnapshotter(ctx, root)
|
o, _, err := newSnapshotter(ctx, root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
key := "/tmp/test"
|
key := "/tmp/test"
|
||||||
mounts, err := o.Prepare(ctx, key, "")
|
mounts, err := o.Prepare(ctx, key, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
m := mounts[0]
|
m := mounts[0]
|
||||||
if err := ioutil.WriteFile(filepath.Join(m.Source, "foo"), []byte("hi"), 0660); err != nil {
|
if err := ioutil.WriteFile(filepath.Join(m.Source, "foo"), []byte("hi"), 0660); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if err := o.Commit(ctx, "base", key); err != nil {
|
if err := o.Commit(ctx, "base", key); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,22 +100,18 @@ func TestOverlayOverlayMount(t *testing.T) {
|
|||||||
defer os.RemoveAll(root)
|
defer os.RemoveAll(root)
|
||||||
o, _, err := newSnapshotter(ctx, root)
|
o, _, err := newSnapshotter(ctx, root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
key := "/tmp/test"
|
key := "/tmp/test"
|
||||||
if _, err = o.Prepare(ctx, key, ""); err != nil {
|
if _, err = o.Prepare(ctx, key, ""); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if err := o.Commit(ctx, "base", key); err != nil {
|
if err := o.Commit(ctx, "base", key); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
var mounts []mount.Mount
|
var mounts []mount.Mount
|
||||||
if mounts, err = o.Prepare(ctx, "/tmp/layer2", "base"); err != nil {
|
if mounts, err = o.Prepare(ctx, "/tmp/layer2", "base"); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if len(mounts) != 1 {
|
if len(mounts) != 1 {
|
||||||
t.Errorf("should only have 1 mount but received %d", len(mounts))
|
t.Errorf("should only have 1 mount but received %d", len(mounts))
|
||||||
@ -194,46 +184,37 @@ func TestOverlayOverlayRead(t *testing.T) {
|
|||||||
defer os.RemoveAll(root)
|
defer os.RemoveAll(root)
|
||||||
o, _, err := newSnapshotter(ctx, root)
|
o, _, err := newSnapshotter(ctx, root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
key := "/tmp/test"
|
key := "/tmp/test"
|
||||||
mounts, err := o.Prepare(ctx, key, "")
|
mounts, err := o.Prepare(ctx, key, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
m := mounts[0]
|
m := mounts[0]
|
||||||
if err := ioutil.WriteFile(filepath.Join(m.Source, "foo"), []byte("hi"), 0660); err != nil {
|
if err := ioutil.WriteFile(filepath.Join(m.Source, "foo"), []byte("hi"), 0660); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if err := o.Commit(ctx, "base", key); err != nil {
|
if err := o.Commit(ctx, "base", key); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if mounts, err = o.Prepare(ctx, "/tmp/layer2", "base"); err != nil {
|
if mounts, err = o.Prepare(ctx, "/tmp/layer2", "base"); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
dest := filepath.Join(root, "dest")
|
dest := filepath.Join(root, "dest")
|
||||||
if err := os.Mkdir(dest, 0700); err != nil {
|
if err := os.Mkdir(dest, 0700); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if err := mount.All(mounts, dest); err != nil {
|
if err := mount.All(mounts, dest); err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer syscall.Unmount(dest, 0)
|
defer syscall.Unmount(dest, 0)
|
||||||
data, err := ioutil.ReadFile(filepath.Join(dest, "foo"))
|
data, err := ioutil.ReadFile(filepath.Join(dest, "foo"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Fatal(err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if e := string(data); e != "hi" {
|
if e := string(data); e != "hi" {
|
||||||
t.Errorf("expected file contents hi but got %q", e)
|
t.Fatalf("expected file contents hi but got %q", e)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user