|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "reflect" |
| 7 | + "time" |
| 8 | + |
| 9 | + "github.com/mndrix/tap-go" |
| 10 | + rspecs "github.com/opencontainers/runtime-spec/specs-go" |
| 11 | + "github.com/opencontainers/runtime-tools/specerror" |
| 12 | + "github.com/opencontainers/runtime-tools/validation/util" |
| 13 | + uuid "github.com/satori/go.uuid" |
| 14 | +) |
| 15 | + |
| 16 | +func main() { |
| 17 | + t := tap.New() |
| 18 | + t.Header(0) |
| 19 | + bundleDir, err := util.PrepareBundle() |
| 20 | + if err != nil { |
| 21 | + util.Fatal(err) |
| 22 | + } |
| 23 | + defer os.RemoveAll(bundleDir) |
| 24 | + |
| 25 | + targetErr := specerror.NewError(specerror.KillNonCreateRunHaveNoEffect, fmt.Errorf("attempting to send a signal to a container that is neither `created` nor `running` MUST have no effect on the container"), rspecs.Version) |
| 26 | + containerID := uuid.NewV4().String() |
| 27 | + g := util.GetDefaultGenerator() |
| 28 | + g.SetProcessArgs([]string{"true"}) |
| 29 | + |
| 30 | + config := util.LifecycleConfig{ |
| 31 | + Config: g, |
| 32 | + BundleDir: bundleDir, |
| 33 | + Actions: util.LifecycleActionCreate | util.LifecycleActionStart | util.LifecycleActionDelete, |
| 34 | + PreCreate: func(r *util.Runtime) error { |
| 35 | + r.SetID(containerID) |
| 36 | + return nil |
| 37 | + }, |
| 38 | + PreDelete: func(r *util.Runtime) error { |
| 39 | + err := util.WaitingForStatus(*r, util.LifecycleStatusStopped, time.Second*5, time.Second*1) |
| 40 | + if err != nil { |
| 41 | + return err |
| 42 | + } |
| 43 | + currentState, err := r.State() |
| 44 | + if err != nil { |
| 45 | + return err |
| 46 | + } |
| 47 | + r.Kill("KILL") |
| 48 | + newState, err := r.State() |
| 49 | + if err != nil || !reflect.DeepEqual(newState, currentState) { |
| 50 | + return targetErr |
| 51 | + } |
| 52 | + return nil |
| 53 | + }, |
| 54 | + } |
| 55 | + err = util.RuntimeLifecycleValidate(config) |
| 56 | + if err != nil && err != targetErr { |
| 57 | + util.Fatal(err) |
| 58 | + } else { |
| 59 | + util.SpecErrorOK(t, err == nil, targetErr, nil) |
| 60 | + } |
| 61 | + t.AutoPlan() |
| 62 | +} |
0 commit comments