summaryrefslogtreecommitdiff
path: root/pkg/hooks/hooks_test.go
diff options
context:
space:
mode:
authorW. Trevor King <wking@tremily.us>2018-05-11 13:03:28 -0700
committerAtomic Bot <atomic-devel@projectatomic.io>2018-05-14 21:36:48 +0000
commit45838b9561977f3e79cf2e61c7ed0dfd9badb303 (patch)
tree40dc9cd883b07f47b36589ff7b77c32c6304f669 /pkg/hooks/hooks_test.go
parent69a6cb255ca98bc7a9e6d47c7a0ccaacab895a25 (diff)
downloadpodman-45838b9561977f3e79cf2e61c7ed0dfd9badb303.tar.gz
podman-45838b9561977f3e79cf2e61c7ed0dfd9badb303.tar.bz2
podman-45838b9561977f3e79cf2e61c7ed0dfd9badb303.zip
hooks: Add package support for extension stages
We aren't consuming this yet, but these pkg/hooks changes lay the groundwork for future libpod changes to support post-exit hooks [1,2]. [1]: https://github.com/projectatomic/libpod/issues/730 [2]: https://github.com/opencontainers/runc/issues/1797 Signed-off-by: W. Trevor King <wking@tremily.us> Closes: #758 Approved by: rhatdan
Diffstat (limited to 'pkg/hooks/hooks_test.go')
-rw-r--r--pkg/hooks/hooks_test.go65
1 files changed, 60 insertions, 5 deletions
diff --git a/pkg/hooks/hooks_test.go b/pkg/hooks/hooks_test.go
index 9da2ec8b0..1b0703556 100644
--- a/pkg/hooks/hooks_test.go
+++ b/pkg/hooks/hooks_test.go
@@ -48,13 +48,13 @@ func TestGoodNew(t *testing.T) {
t.Fatal(err)
}
- manager, err := New(ctx, []string{dir}, lang)
+ manager, err := New(ctx, []string{dir}, []string{}, lang)
if err != nil {
t.Fatal(err)
}
config := &rspec.Spec{}
- err = manager.Hooks(config, map[string]string{}, false)
+ extensionStages, err := manager.Hooks(config, map[string]string{}, false)
if err != nil {
t.Fatal(err)
}
@@ -90,6 +90,9 @@ func TestGoodNew(t *testing.T) {
},
},
}, config.Hooks)
+
+ var nilExtensionStages map[string][]rspec.Hook
+ assert.Equal(t, nilExtensionStages, extensionStages)
}
func TestBadNew(t *testing.T) {
@@ -112,7 +115,7 @@ func TestBadNew(t *testing.T) {
t.Fatal(err)
}
- _, err = New(ctx, []string{dir}, lang)
+ _, err = New(ctx, []string{dir}, []string{}, lang)
if err == nil {
t.Fatal("unexpected success")
}
@@ -139,11 +142,14 @@ func TestBrokenMatch(t *testing.T) {
Args: []string{"/bin/sh"},
},
}
- err := manager.Hooks(config, map[string]string{}, false)
+ extensionStages, err := manager.Hooks(config, map[string]string{}, false)
if err == nil {
t.Fatal("unexpected success")
}
assert.Regexp(t, "^matching hook \"a\\.json\": command: error parsing regexp: .*", err.Error())
+
+ var nilExtensionStages map[string][]rspec.Hook
+ assert.Equal(t, nilExtensionStages, extensionStages)
}
func TestInvalidStage(t *testing.T) {
@@ -162,11 +168,60 @@ func TestInvalidStage(t *testing.T) {
},
},
}
- err := manager.Hooks(&rspec.Spec{}, map[string]string{}, false)
+ extensionStages, err := manager.Hooks(&rspec.Spec{}, map[string]string{}, false)
if err == nil {
t.Fatal("unexpected success")
}
assert.Regexp(t, "^hook \"a\\.json\": unknown stage \"does-not-exist\"$", err.Error())
+
+ var nilExtensionStages map[string][]rspec.Hook
+ assert.Equal(t, nilExtensionStages, extensionStages)
+}
+
+func TestExtensionStage(t *testing.T) {
+ always := true
+ manager := Manager{
+ hooks: map[string]*current.Hook{
+ "a.json": {
+ Version: current.Version,
+ Hook: rspec.Hook{
+ Path: "/a/b/c",
+ },
+ When: current.When{
+ Always: &always,
+ },
+ Stages: []string{"prestart", "a", "b"},
+ },
+ },
+ extensionStages: []string{"a", "b", "c"},
+ }
+
+ config := &rspec.Spec{}
+ extensionStages, err := manager.Hooks(config, map[string]string{}, false)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ assert.Equal(t, &rspec.Hooks{
+ Prestart: []rspec.Hook{
+ {
+ Path: "/a/b/c",
+ },
+ },
+ }, config.Hooks)
+
+ assert.Equal(t, map[string][]rspec.Hook{
+ "a": {
+ {
+ Path: "/a/b/c",
+ },
+ },
+ "b": {
+ {
+ Path: "/a/b/c",
+ },
+ },
+ }, extensionStages)
}
func init() {