aboutsummaryrefslogtreecommitdiff
path: root/libpod/container_internal_test.go
diff options
context:
space:
mode:
authorW. Trevor King <wking@tremily.us>2018-05-31 11:47:17 -0700
committerAtomic Bot <atomic-devel@projectatomic.io>2018-06-04 18:36:40 +0000
commitc9f763456cd8263c3f2d84c6b2b6e17ad81cf3ba (patch)
treeb1cffd82978145f372893f62754432d75003b31d /libpod/container_internal_test.go
parent28d1cec9f64cca11d42410c6e33c43b01b1d7678 (diff)
downloadpodman-c9f763456cd8263c3f2d84c6b2b6e17ad81cf3ba.tar.gz
podman-c9f763456cd8263c3f2d84c6b2b6e17ad81cf3ba.tar.bz2
podman-c9f763456cd8263c3f2d84c6b2b6e17ad81cf3ba.zip
libpod: Execute poststop hooks locally
Instead of delegating to the runtime, since some runtimes do not seem to handle these reliably [1]. [1]: https://github.com/projectatomic/libpod/issues/730#issuecomment-392959938 Signed-off-by: W. Trevor King <wking@tremily.us> Closes: #864 Approved by: rhatdan
Diffstat (limited to 'libpod/container_internal_test.go')
-rw-r--r--libpod/container_internal_test.go80
1 files changed, 80 insertions, 0 deletions
diff --git a/libpod/container_internal_test.go b/libpod/container_internal_test.go
new file mode 100644
index 000000000..78891a672
--- /dev/null
+++ b/libpod/container_internal_test.go
@@ -0,0 +1,80 @@
+package libpod
+
+import (
+ "context"
+ "fmt"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+ "runtime"
+ "testing"
+
+ rspec "github.com/opencontainers/runtime-spec/specs-go"
+ "github.com/stretchr/testify/assert"
+)
+
+// hookPath is the path to an example hook executable.
+var hookPath string
+
+func TestPostDeleteHooks(t *testing.T) {
+ ctx := context.Background()
+ dir, err := ioutil.TempDir("", "libpod_test_")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer os.RemoveAll(dir)
+
+ statePath := filepath.Join(dir, "state")
+ copyPath := filepath.Join(dir, "copy")
+ c := Container{
+ config: &ContainerConfig{
+ ID: "123abc",
+ Spec: &rspec.Spec{
+ Annotations: map[string]string{
+ "a": "b",
+ },
+ },
+ StaticDir: dir, // not the bundle, but good enough for this test
+ },
+ state: &containerState{
+ ExtensionStageHooks: map[string][]rspec.Hook{
+ "poststop": {
+ rspec.Hook{
+ Path: hookPath,
+ Args: []string{"sh", "-c", fmt.Sprintf("cat >%s", statePath)},
+ },
+ rspec.Hook{
+ Path: "/does/not/exist",
+ },
+ rspec.Hook{
+ Path: hookPath,
+ Args: []string{"sh", "-c", fmt.Sprintf("cp %s %s", statePath, copyPath)},
+ },
+ },
+ },
+ },
+ }
+ err = c.postDeleteHooks(ctx)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ stateRegexp := "{\"ociVersion\":\"1\\.0\\.0\",\"id\":\"123abc\",\"status\":\"stopped\",\"bundle\":\"/tmp/libpod_test_[0-9]*\",\"annotations\":{\"a\":\"b\"}}"
+ for _, path := range []string{statePath, copyPath} {
+ t.Run(path, func(t *testing.T) {
+ content, err := ioutil.ReadFile(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ assert.Regexp(t, stateRegexp, string(content))
+ })
+ }
+}
+
+func init() {
+ if runtime.GOOS != "windows" {
+ hookPath = "/bin/sh"
+ } else {
+ panic("we need a reliable executable path on Windows")
+ }
+}