@@ -2,6 +2,7 @@ package integration
22
33import (
44 "bytes"
5+ "encoding/json"
56 "fmt"
67 "io/ioutil"
78 "os"
@@ -1048,25 +1049,44 @@ func TestHook(t *testing.T) {
10481049 if testing .Short () {
10491050 return
10501051 }
1051- root , err := newTestRoot ()
1052+
1053+ bundle , err := newTestBundle ()
10521054 ok (t , err )
1053- defer os . RemoveAll ( root )
1055+ defer remove ( bundle )
10541056
10551057 rootfs , err := newRootfs ()
10561058 ok (t , err )
10571059 defer remove (rootfs )
10581060
10591061 config := newTemplateConfig (rootfs )
1060- expectedBundlePath := "/path/to/ bundle/path"
1062+ expectedBundlePath := bundle
10611063 config .Labels = append (config .Labels , fmt .Sprintf ("bundle=%s" , expectedBundlePath ))
1064+
1065+ getRootfsFromBundle := func (bundle string ) (string , error ) {
1066+ f , err := os .Open (filepath .Join (bundle , "config.json" ))
1067+ if err != nil {
1068+ return "" , err
1069+ }
1070+
1071+ var config configs.Config
1072+ if err = json .NewDecoder (f ).Decode (& config ); err != nil {
1073+ return "" , err
1074+ }
1075+ return config .Rootfs , nil
1076+ }
1077+
10621078 config .Hooks = & configs.Hooks {
10631079 Prestart : []configs.Hook {
10641080 configs .NewFunctionHook (func (s configs.HookState ) error {
10651081 if s .BundlePath != expectedBundlePath {
10661082 t .Fatalf ("Expected prestart hook bundlePath '%s'; got '%s'" , expectedBundlePath , s .BundlePath )
10671083 }
10681084
1069- f , err := os .Create (filepath .Join (s .Root , "test" ))
1085+ root , err := getRootfsFromBundle (s .BundlePath )
1086+ if err != nil {
1087+ return err
1088+ }
1089+ f , err := os .Create (filepath .Join (root , "test" ))
10701090 if err != nil {
10711091 return err
10721092 }
@@ -1079,7 +1099,11 @@ func TestHook(t *testing.T) {
10791099 t .Fatalf ("Expected poststart hook bundlePath '%s'; got '%s'" , expectedBundlePath , s .BundlePath )
10801100 }
10811101
1082- return ioutil .WriteFile (filepath .Join (s .Root , "test" ), []byte ("hello world" ), 0755 )
1102+ root , err := getRootfsFromBundle (s .BundlePath )
1103+ if err != nil {
1104+ return err
1105+ }
1106+ return ioutil .WriteFile (filepath .Join (root , "test" ), []byte ("hello world" ), 0755 )
10831107 }),
10841108 },
10851109 Poststop : []configs.Hook {
@@ -1088,10 +1112,20 @@ func TestHook(t *testing.T) {
10881112 t .Fatalf ("Expected poststop hook bundlePath '%s'; got '%s'" , expectedBundlePath , s .BundlePath )
10891113 }
10901114
1091- return os .RemoveAll (filepath .Join (s .Root , "test" ))
1115+ root , err := getRootfsFromBundle (s .BundlePath )
1116+ if err != nil {
1117+ return err
1118+ }
1119+ return os .RemoveAll (filepath .Join (root , "test" ))
10921120 }),
10931121 },
10941122 }
1123+
1124+ // write config of json format into config.json under bundle
1125+ f , err := os .OpenFile (filepath .Join (bundle , "config.json" ), os .O_CREATE | os .O_RDWR , 0644 )
1126+ ok (t , err )
1127+ ok (t , json .NewEncoder (f ).Encode (config ))
1128+
10951129 container , err := factory .Create ("test" , config )
10961130 ok (t , err )
10971131
0 commit comments