Add NewContainer and Delete container support
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package containerd
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const defaultAddress = "/run/containerd/containerd.sock"
|
||||
|
||||
@@ -16,3 +19,38 @@ func TestNewClient(t *testing.T) {
|
||||
t.Errorf("client closed returned errror %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewContainer(t *testing.T) {
|
||||
client, err := New(defaultAddress)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
id := "test"
|
||||
spec, err := GenerateSpec(WithHostname(id))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
container, err := client.NewContainer(context.Background(), id, spec)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if container.ID() != id {
|
||||
t.Errorf("expected container id %q but received %q", id, container.ID())
|
||||
}
|
||||
if spec, err = container.Spec(); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if spec.Hostname != id {
|
||||
t.Errorf("expected spec hostname id %q but received %q", id, container.ID())
|
||||
return
|
||||
}
|
||||
if err := container.Delete(context.Background()); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user