diff options
author | W. Trevor King <wking@tremily.us> | 2018-05-11 13:03:28 -0700 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-05-14 21:36:48 +0000 |
commit | 45838b9561977f3e79cf2e61c7ed0dfd9badb303 (patch) | |
tree | 40dc9cd883b07f47b36589ff7b77c32c6304f669 /pkg/hooks/1.0.0 | |
parent | 69a6cb255ca98bc7a9e6d47c7a0ccaacab895a25 (diff) | |
download | podman-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/1.0.0')
-rw-r--r-- | pkg/hooks/1.0.0/hook.go | 6 | ||||
-rw-r--r-- | pkg/hooks/1.0.0/hook_test.go | 34 |
2 files changed, 29 insertions, 11 deletions
diff --git a/pkg/hooks/1.0.0/hook.go b/pkg/hooks/1.0.0/hook.go index cf623ee42..77fbab5aa 100644 --- a/pkg/hooks/1.0.0/hook.go +++ b/pkg/hooks/1.0.0/hook.go @@ -31,7 +31,7 @@ func Read(content []byte) (hook *Hook, err error) { } // Validate performs load-time hook validation. -func (hook *Hook) Validate() (err error) { +func (hook *Hook) Validate(extensionStages []string) (err error) { if hook == nil { return errors.New("nil hook") } @@ -68,6 +68,10 @@ func (hook *Hook) Validate() (err error) { } validStages := map[string]bool{"prestart": true, "poststart": true, "poststop": true} + for _, stage := range extensionStages { + validStages[stage] = true + } + for _, stage := range hook.Stages { if !validStages[stage] { return fmt.Errorf("unknown stage %q", stage) diff --git a/pkg/hooks/1.0.0/hook_test.go b/pkg/hooks/1.0.0/hook_test.go index 003be34bb..bd6d6b654 100644 --- a/pkg/hooks/1.0.0/hook_test.go +++ b/pkg/hooks/1.0.0/hook_test.go @@ -51,7 +51,7 @@ func TestGoodValidate(t *testing.T) { }, Stages: []string{"prestart"}, } - err := hook.Validate() + err := hook.Validate([]string{}) if err != nil { t.Fatal(err) } @@ -59,7 +59,7 @@ func TestGoodValidate(t *testing.T) { func TestNilValidation(t *testing.T) { var hook *Hook - err := hook.Validate() + err := hook.Validate([]string{}) if err == nil { t.Fatal("unexpected success") } @@ -68,7 +68,7 @@ func TestNilValidation(t *testing.T) { func TestWrongVersion(t *testing.T) { hook := Hook{Version: "0.1.0"} - err := hook.Validate() + err := hook.Validate([]string{}) if err == nil { t.Fatal("unexpected success") } @@ -80,7 +80,7 @@ func TestNoHookPath(t *testing.T) { Version: "1.0.0", Hook: rspec.Hook{}, } - err := hook.Validate() + err := hook.Validate([]string{}) if err == nil { t.Fatal("unexpected success") } @@ -94,7 +94,7 @@ func TestUnknownHookPath(t *testing.T) { Path: filepath.Join("does", "not", "exist"), }, } - err := hook.Validate() + err := hook.Validate([]string{}) if err == nil { t.Fatal("unexpected success") } @@ -111,7 +111,7 @@ func TestNoStages(t *testing.T) { Path: path, }, } - err := hook.Validate() + err := hook.Validate([]string{}) if err == nil { t.Fatal("unexpected success") } @@ -126,13 +126,27 @@ func TestInvalidStage(t *testing.T) { }, Stages: []string{"does-not-exist"}, } - err := hook.Validate() + err := hook.Validate([]string{}) if err == nil { t.Fatal("unexpected success") } assert.Regexp(t, "^unknown stage \"does-not-exist\"$", err.Error()) } +func TestExtensionStage(t *testing.T) { + hook := Hook{ + Version: "1.0.0", + Hook: rspec.Hook{ + Path: path, + }, + Stages: []string{"prestart", "b"}, + } + err := hook.Validate([]string{"a", "b", "c"}) + if err != nil { + t.Fatal(err) + } +} + func TestInvalidAnnotationKey(t *testing.T) { hook := Hook{ Version: "1.0.0", @@ -146,7 +160,7 @@ func TestInvalidAnnotationKey(t *testing.T) { }, Stages: []string{"prestart"}, } - err := hook.Validate() + err := hook.Validate([]string{}) if err == nil { t.Fatal("unexpected success") } @@ -166,7 +180,7 @@ func TestInvalidAnnotationValue(t *testing.T) { }, Stages: []string{"prestart"}, } - err := hook.Validate() + err := hook.Validate([]string{}) if err == nil { t.Fatal("unexpected success") } @@ -184,7 +198,7 @@ func TestInvalidCommand(t *testing.T) { }, Stages: []string{"prestart"}, } - err := hook.Validate() + err := hook.Validate([]string{}) if err == nil { t.Fatal("unexpected success") } |