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"
|
||||
|
||||
func TestNewClient(t *testing.T) {
|
||||
if testing.Short() {
|
||||
return
|
||||
}
|
||||
client, err := New(defaultAddress)
|
||||
if err != nil {
|
||||
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) {
|
||||
if testing.Short() {
|
||||
return
|
||||
}
|
||||
client, err := New(defaultAddress)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -6,6 +6,9 @@ import (
|
||||
)
|
||||
|
||||
func TestContainerList(t *testing.T) {
|
||||
if testing.Short() {
|
||||
return
|
||||
}
|
||||
client, err := New(defaultAddress)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -21,3 +24,37 @@ func TestContainerList(t *testing.T) {
|
||||
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
|
||||
// for use as a containerd container
|
||||
func GenerateSpec(id string, opts ...SpecOpts) (*specs.Spec, error) {
|
||||
s, err := createDefaultSpec(id)
|
||||
func GenerateSpec(opts ...SpecOpts) (*specs.Spec, error) {
|
||||
s, err := createDefaultSpec()
|
||||
if err != nil {
|
||||
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{
|
||||
Version: specs.Version,
|
||||
Platform: specs.Platform{
|
||||
@ -67,7 +67,6 @@ func createDefaultSpec(id string) (*specs.Spec, error) {
|
||||
Root: specs.Root{
|
||||
Path: defaultRootfsPath,
|
||||
},
|
||||
Hostname: id,
|
||||
Process: specs.Process{
|
||||
Cwd: "/",
|
||||
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) {
|
||||
cerr := t.io.Close()
|
||||
r, err := t.client.tasks().Delete(ctx, &execution.DeleteRequest{
|
||||
t.containerID,
|
||||
ContainerID: t.containerID,
|
||||
})
|
||||
if err != nil {
|
||||
return 255, err
|
||||
|
Loading…
Reference in New Issue
Block a user