|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "path/filepath" |
| 7 | + "time" |
| 8 | + |
| 9 | + tap "github.com/mndrix/tap-go" |
| 10 | + "github.com/mrunalp/fileutils" |
| 11 | + rspec "github.com/opencontainers/runtime-spec/specs-go" |
| 12 | + "github.com/opencontainers/runtime-tools/generate" |
| 13 | + "github.com/opencontainers/runtime-tools/specerror" |
| 14 | + "github.com/opencontainers/runtime-tools/validation/util" |
| 15 | + uuid "github.com/satori/go.uuid" |
| 16 | +) |
| 17 | + |
| 18 | +func main() { |
| 19 | + t := tap.New() |
| 20 | + t.Header(0) |
| 21 | + |
| 22 | + bundleDir, err := util.PrepareBundle() |
| 23 | + if err != nil { |
| 24 | + util.Fatal(err) |
| 25 | + } |
| 26 | + defer os.RemoveAll(bundleDir) |
| 27 | + |
| 28 | + r, err := util.NewRuntime(util.RuntimeCommand, bundleDir) |
| 29 | + if err != nil { |
| 30 | + util.Fatal(err) |
| 31 | + } |
| 32 | + |
| 33 | + testPath := filepath.Join(bundleDir, "test.json") |
| 34 | + r.SetID(uuid.NewV4().String()) |
| 35 | + // generate a config has all the testing properties |
| 36 | + g, err := util.GetDefaultGenerator() |
| 37 | + if err != nil { |
| 38 | + util.Fatal(err) |
| 39 | + } |
| 40 | + g.SetProcessArgs([]string{"/runtimetest", "--path=/test.json"}) |
| 41 | + g.AddLinuxMaskedPaths("/proc/kcore") |
| 42 | + g.AddLinuxReadonlyPaths("/proc/fs") |
| 43 | + g.AddLinuxSysctl("net.ipv4.ip_forward", "1") |
| 44 | + g.SetProcessOOMScoreAdj(100) |
| 45 | + g.AddProcessRlimits("RLIMIT_NOFILE", 1024, 1024) |
| 46 | + g.SetLinuxRootPropagation("shared") |
| 47 | + |
| 48 | + err = r.SetConfig(g) |
| 49 | + if err != nil { |
| 50 | + util.Fatal(err) |
| 51 | + } |
| 52 | + |
| 53 | + err = g.SaveToFile(testPath, generate.ExportOptions{}) |
| 54 | + if err != nil { |
| 55 | + util.Fatal(err) |
| 56 | + } |
| 57 | + |
| 58 | + err = fileutils.CopyFile("runtimetest", filepath.Join(r.BundleDir, "runtimetest")) |
| 59 | + if err != nil { |
| 60 | + util.Fatal(err) |
| 61 | + } |
| 62 | + |
| 63 | + err = r.Create() |
| 64 | + if err != nil { |
| 65 | + util.Fatal(err) |
| 66 | + } |
| 67 | + |
| 68 | + spec := &rspec.Spec{ |
| 69 | + Version: "1.0.0", |
| 70 | + } |
| 71 | + g.SetSpec(spec) |
| 72 | + err = r.SetConfig(g) |
| 73 | + if err != nil { |
| 74 | + util.Fatal(err) |
| 75 | + } |
| 76 | + |
| 77 | + err = r.Start() |
| 78 | + util.SpecErrorOK(t, err == nil, specerror.NewError(specerror.ConfigUpdatesWithoutAffect, fmt.Errorf("Any updates to config.json after this step MUST NOT affect the container"), rspec.Version), nil) |
| 79 | + |
| 80 | + err = util.WaitingForStatus(r, util.LifecycleStatusStopped, time.Second*10, time.Second*1) |
| 81 | + if err == nil { |
| 82 | + err = r.Delete() |
| 83 | + } |
| 84 | + if err != nil { |
| 85 | + util.Fatal(err) |
| 86 | + } |
| 87 | + |
| 88 | + t.AutoPlan() |
| 89 | +} |
0 commit comments