|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "github.com/mndrix/tap-go" |
| 7 | + rspecs "github.com/opencontainers/runtime-spec/specs-go" |
| 8 | + "github.com/opencontainers/runtime-tools/generate" |
| 9 | + "github.com/opencontainers/runtime-tools/specerror" |
| 10 | + "github.com/opencontainers/runtime-tools/validation/util" |
| 11 | + "github.com/satori/go.uuid" |
| 12 | +) |
| 13 | + |
| 14 | +func main() { |
| 15 | + t := tap.New() |
| 16 | + |
| 17 | + g := generate.New() |
| 18 | + g.SetRootPath(".") |
| 19 | + g.SetProcessArgs([]string{"ls"}) |
| 20 | + |
| 21 | + bundleDir, err := util.PrepareBundle() |
| 22 | + if err != nil { |
| 23 | + util.Fatal(err) |
| 24 | + } |
| 25 | + |
| 26 | + r, err := util.NewRuntime(util.RuntimeCommand, bundleDir) |
| 27 | + if err != nil { |
| 28 | + util.Fatal(err) |
| 29 | + } |
| 30 | + defer r.Clean(true) |
| 31 | + |
| 32 | + err = r.SetConfig(&g) |
| 33 | + if err != nil { |
| 34 | + util.Fatal(err) |
| 35 | + } |
| 36 | + |
| 37 | + containerID := uuid.NewV4().String() |
| 38 | + cases := []struct { |
| 39 | + id string |
| 40 | + errExpected bool |
| 41 | + err error |
| 42 | + }{ |
| 43 | + {"", false, specerror.NewError(specerror.CreateWithBundlePathAndID, fmt.Errorf("create MUST generate an error if the ID is not provided"), rspecs.Version)}, |
| 44 | + {containerID, true, specerror.NewError(specerror.CreateNewContainer, fmt.Errorf("create MUST create a new container"), rspecs.Version)}, |
| 45 | + {containerID, false, specerror.NewError(specerror.CreateWithUniqueID, fmt.Errorf("create MUST generate an error if the ID provided is not unique"), rspecs.Version)}, |
| 46 | + } |
| 47 | + |
| 48 | + for _, c := range cases { |
| 49 | + r.SetID(c.id) |
| 50 | + stderr, err := r.Create() |
| 51 | + t.Ok((err == nil) == c.errExpected, c.err.(*specerror.Error).Err.Err.Error()) |
| 52 | + t.Diagnostic(c.err.(*specerror.Error).Err.Reference) |
| 53 | + t.Diagnostic(err.Error()) |
| 54 | + if len(stderr) > 0 { |
| 55 | + t.Diagnostic(string(stderr)) |
| 56 | + } |
| 57 | + |
| 58 | + if err == nil { |
| 59 | + state, _ := r.State() |
| 60 | + t.Ok(state.ID == c.id, "") |
| 61 | + t.Diagnosticf("container PID: %d, state ID: %d", c.id, state.ID) |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + t.AutoPlan() |
| 66 | +} |
0 commit comments