forked from opencontainers/runtime-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.go
More file actions
75 lines (64 loc) · 1.87 KB
/
create.go
File metadata and controls
75 lines (64 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"github.com/mndrix/tap-go"
rspecs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/generate"
"github.com/opencontainers/runtime-tools/specerror"
"github.com/opencontainers/runtime-tools/validation/util"
"github.com/satori/go.uuid"
)
func main() {
t := tap.New()
t.Header(0)
g := generate.New()
g.SetRootPath(".")
g.SetProcessArgs([]string{"ls"})
bundleDir, err := util.PrepareBundle()
if err != nil {
util.Fatal(err)
}
r, err := util.NewRuntime(util.RuntimeCommand, bundleDir)
if err != nil {
util.Fatal(err)
}
defer r.Clean(true, true)
err = r.SetConfig(&g)
if err != nil {
util.Fatal(err)
}
containerID := uuid.NewV4().String()
cases := []struct {
id string
errExpected bool
err error
}{
{"", false, specerror.NewError(specerror.CreateWithBundlePathAndID, fmt.Errorf("create MUST generate an error if the ID is not provided"), rspecs.Version)},
{containerID, true, specerror.NewError(specerror.CreateNewContainer, fmt.Errorf("create MUST create a new container"), rspecs.Version)},
{containerID, false, specerror.NewError(specerror.CreateWithUniqueID, fmt.Errorf("create MUST generate an error if the ID provided is not unique"), rspecs.Version)},
}
for _, c := range cases {
r.SetID(c.id)
stderr, err := r.Create()
t.Ok((err == nil) == c.errExpected, c.err.(*specerror.Error).Err.Err.Error())
diagnostic := map[string]string{
"reference": c.err.(*specerror.Error).Err.Reference,
}
if err != nil {
diagnostic["error"] = err.Error()
}
if len(stderr) > 0 {
diagnostic["stderr"] = string(stderr)
}
t.YAML(diagnostic)
if err == nil {
state, _ := r.State()
t.Ok(state.ID == c.id, "'state' MUST return the state of a container")
t.YAML(map[string]string{
"container ID": c.id,
"state ID": state.ID,
})
}
}
t.AutoPlan()
}