From 5bb81469895d669ddcb4b49e83809a980d57d6b1 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Tue, 23 Dec 2014 11:13:45 -0800 Subject: [PATCH] Add Contains wrapper for Namespaces type Signed-off-by: Alexander Morozov --- config.go | 4 ++++ config_test.go | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index bf5236555..7f1bcc962 100644 --- a/config.go +++ b/config.go @@ -57,6 +57,10 @@ func (n Namespaces) index(t NamespaceType) int { return -1 } +func (n Namespaces) Contains(t NamespaceType) bool { + return n.index(t) != -1 +} + // Config defines configuration options for executing a process inside a contained environment. type Config struct { // Mount specific options. diff --git a/config_test.go b/config_test.go index 63b8aa8ad..5c73f84af 100644 --- a/config_test.go +++ b/config_test.go @@ -64,12 +64,12 @@ func TestConfigJsonFormat(t *testing.T) { t.Fail() } - if container.Namespaces.index(NEWNET) == -1 { + if !container.Namespaces.Contains(NEWNET) { t.Log("namespaces should contain NEWNET") t.Fail() } - if container.Namespaces.index(NEWUSER) != -1 { + if container.Namespaces.Contains(NEWUSER) { t.Log("namespaces should not contain NEWUSER") t.Fail() }