Skip to content

Commit

Permalink
validation: Implement ConfigUpdatesWithoutAffect
Browse files Browse the repository at this point in the history
Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>
  • Loading branch information
Zhou Hao committed Mar 20, 2018
1 parent 3f64e51 commit 4cf14f6
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions validation/config_updates_without_affect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package main

import (
"fmt"
"os"
"path/filepath"
"time"

tap "github.com/mndrix/tap-go"
"github.com/mrunalp/fileutils"
rspec "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"
uuid "github.com/satori/go.uuid"
)

func main() {
t := tap.New()
t.Header(0)

bundleDir, err := util.PrepareBundle()
if err != nil {
util.Fatal(err)
}
defer os.RemoveAll(bundleDir)

r, err := util.NewRuntime(util.RuntimeCommand, bundleDir)
if err != nil {
util.Fatal(err)
}

testPath := filepath.Join("/", "test", "config.json")
r.SetID(uuid.NewV4().String())
g := util.GetDefaultGenerator()
g.SetProcessArgs([]string{"/runtimetest", "--path=" + testPath})

err = r.SetConfig(g)
if err != nil {
util.Fatal(err)
}

err = g.SaveToFile(testPath, generate.ExportOptions{})
if err != nil {
util.Fatal(err)
}

err = fileutils.CopyFile("runtimetest", filepath.Join(r.BundleDir, "runtimetest"))
if err != nil {
util.Fatal(err)
}

err = r.Create()
if err != nil {
util.Fatal(err)
}

spec := &rspec.Spec{
Version: "1.0.0",
}
g.SetSpec(spec)
err = r.SetConfig(g)
if err != nil {
util.Fatal(err)
}

err = r.Start()
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)

err = util.WaitingForStatus(r, util.LifecycleStatusStopped, time.Second*10, time.Second*1)
if err == nil {
err = r.Delete()
}
if err != nil {
util.Fatal(err)
}

t.AutoPlan()
}

0 comments on commit 4cf14f6

Please sign in to comment.