Add test -short for non-integration tests
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
01c4c86414
commit
8cd882c570
@ -8,6 +8,9 @@ import (
|
|||||||
const defaultAddress = "/run/containerd/containerd.sock"
|
const defaultAddress = "/run/containerd/containerd.sock"
|
||||||
|
|
||||||
func TestNewClient(t *testing.T) {
|
func TestNewClient(t *testing.T) {
|
||||||
|
if testing.Short() {
|
||||||
|
return
|
||||||
|
}
|
||||||
client, err := New(defaultAddress)
|
client, err := New(defaultAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -20,42 +23,10 @@ func TestNewClient(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestImagePull(t *testing.T) {
|
func TestImagePull(t *testing.T) {
|
||||||
|
if testing.Short() {
|
||||||
|
return
|
||||||
|
}
|
||||||
client, err := New(defaultAddress)
|
client, err := New(defaultAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -6,6 +6,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestContainerList(t *testing.T) {
|
func TestContainerList(t *testing.T) {
|
||||||
|
if testing.Short() {
|
||||||
|
return
|
||||||
|
}
|
||||||
client, err := New(defaultAddress)
|
client, err := New(defaultAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -21,3 +24,37 @@ func TestContainerList(t *testing.T) {
|
|||||||
t.Errorf("expected 0 containers but received %d", len(containers))
|
t.Errorf("expected 0 containers but received %d", len(containers))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewContainer(t *testing.T) {
|
||||||
|
if testing.Short() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
client, err := New(defaultAddress)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer client.Close()
|
||||||
|
|
||||||
|
id := "test"
|
||||||
|
spec, err := GenerateSpec()
|
||||||
|
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 err := container.Delete(context.Background()); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
4
spec.go
4
spec.go
@ -23,8 +23,8 @@ func WithArgs(args ...string) SpecOpts {
|
|||||||
|
|
||||||
// GenerateSpec will generate a default spec from the provided image
|
// GenerateSpec will generate a default spec from the provided image
|
||||||
// for use as a containerd container
|
// for use as a containerd container
|
||||||
func GenerateSpec(id string, opts ...SpecOpts) (*specs.Spec, error) {
|
func GenerateSpec(opts ...SpecOpts) (*specs.Spec, error) {
|
||||||
s, err := createDefaultSpec(id)
|
s, err := createDefaultSpec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ func defaultNamespaces() []specs.LinuxNamespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createDefaultSpec(id string) (*specs.Spec, error) {
|
func createDefaultSpec() (*specs.Spec, error) {
|
||||||
s := &specs.Spec{
|
s := &specs.Spec{
|
||||||
Version: specs.Version,
|
Version: specs.Version,
|
||||||
Platform: specs.Platform{
|
Platform: specs.Platform{
|
||||||
@ -67,7 +67,6 @@ func createDefaultSpec(id string) (*specs.Spec, error) {
|
|||||||
Root: specs.Root{
|
Root: specs.Root{
|
||||||
Path: defaultRootfsPath,
|
Path: defaultRootfsPath,
|
||||||
},
|
},
|
||||||
Hostname: id,
|
|
||||||
Process: specs.Process{
|
Process: specs.Process{
|
||||||
Cwd: "/",
|
Cwd: "/",
|
||||||
NoNewPrivileges: true,
|
NoNewPrivileges: true,
|
||||||
|
2
task.go
2
task.go
@ -215,7 +215,7 @@ func (t *Task) Wait(ctx context.Context) (uint32, error) {
|
|||||||
func (t *Task) Delete(ctx context.Context) (uint32, error) {
|
func (t *Task) Delete(ctx context.Context) (uint32, error) {
|
||||||
cerr := t.io.Close()
|
cerr := t.io.Close()
|
||||||
r, err := t.client.tasks().Delete(ctx, &execution.DeleteRequest{
|
r, err := t.client.tasks().Delete(ctx, &execution.DeleteRequest{
|
||||||
t.containerID,
|
ContainerID: t.containerID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 255, err
|
return 255, err
|
||||||
|
Loading…
Reference in New Issue
Block a user