You've already forked runc
mirror of
https://github.com/opencontainers/runc.git
synced 2025-07-30 17:43:06 +03:00
sync up HookState
with OCI spec State
`HookState` struct should follow definition of `State` in runtime-spec: * modify json name of `version` to `ociVersion`. * Remove redundant `Rootfs` field as rootfs can be retrived from `bundlePath/config.json`. Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
This commit is contained in:
@ -2,6 +2,7 @@ package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@ -1048,17 +1049,32 @@ func TestHook(t *testing.T) {
|
||||
if testing.Short() {
|
||||
return
|
||||
}
|
||||
root, err := newTestRoot()
|
||||
|
||||
bundle, err := newTestBundle()
|
||||
ok(t, err)
|
||||
defer os.RemoveAll(root)
|
||||
defer remove(bundle)
|
||||
|
||||
rootfs, err := newRootfs()
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
expectedBundlePath := "/path/to/bundle/path"
|
||||
expectedBundlePath := bundle
|
||||
config.Labels = append(config.Labels, fmt.Sprintf("bundle=%s", expectedBundlePath))
|
||||
|
||||
getRootfsFromBundle := func(bundle string) (string, error) {
|
||||
f, err := os.Open(filepath.Join(bundle, "config.json"))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var config configs.Config
|
||||
if err = json.NewDecoder(f).Decode(&config); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return config.Rootfs, nil
|
||||
}
|
||||
|
||||
config.Hooks = &configs.Hooks{
|
||||
Prestart: []configs.Hook{
|
||||
configs.NewFunctionHook(func(s configs.HookState) error {
|
||||
@ -1066,7 +1082,11 @@ func TestHook(t *testing.T) {
|
||||
t.Fatalf("Expected prestart hook bundlePath '%s'; got '%s'", expectedBundlePath, s.BundlePath)
|
||||
}
|
||||
|
||||
f, err := os.Create(filepath.Join(s.Root, "test"))
|
||||
root, err := getRootfsFromBundle(s.BundlePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f, err := os.Create(filepath.Join(root, "test"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -1079,7 +1099,11 @@ func TestHook(t *testing.T) {
|
||||
t.Fatalf("Expected poststart hook bundlePath '%s'; got '%s'", expectedBundlePath, s.BundlePath)
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(filepath.Join(s.Root, "test"), []byte("hello world"), 0755)
|
||||
root, err := getRootfsFromBundle(s.BundlePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ioutil.WriteFile(filepath.Join(root, "test"), []byte("hello world"), 0755)
|
||||
}),
|
||||
},
|
||||
Poststop: []configs.Hook{
|
||||
@ -1088,10 +1112,20 @@ func TestHook(t *testing.T) {
|
||||
t.Fatalf("Expected poststop hook bundlePath '%s'; got '%s'", expectedBundlePath, s.BundlePath)
|
||||
}
|
||||
|
||||
return os.RemoveAll(filepath.Join(s.Root, "test"))
|
||||
root, err := getRootfsFromBundle(s.BundlePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.RemoveAll(filepath.Join(root, "test"))
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
// write config of json format into config.json under bundle
|
||||
f, err := os.OpenFile(filepath.Join(bundle, "config.json"), os.O_CREATE|os.O_RDWR, 0644)
|
||||
ok(t, err)
|
||||
ok(t, json.NewEncoder(f).Encode(config))
|
||||
|
||||
container, err := factory.Create("test", config)
|
||||
ok(t, err)
|
||||
|
||||
|
Reference in New Issue
Block a user