From b85b217f55993955da9ad0cae7735747b2f24390 Mon Sep 17 00:00:00 2001 From: baude Date: Thu, 8 Mar 2018 15:45:52 -0600 Subject: Stage3 Image Library This represents the stage3 implementation for the image library. At this point, we are moving the image-centric functions to pkg/image including migration of args and object-oriented references. This is a not a one-for-one migration of funcs and some funcs will need to continue to reside in runtime_img as they are overly specific to libpod and probably not useful to others. Signed-off-by: baude Closes: #484 Approved by: baude --- pkg/util/utils.go | 10 ++++++++++ pkg/util/utils_test.go | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 pkg/util/utils_test.go (limited to 'pkg') diff --git a/pkg/util/utils.go b/pkg/util/utils.go index 9a93021e4..edcf63f80 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -44,3 +44,13 @@ func ParseRegistryCreds(creds string) (*types.DockerAuthConfig, error) { Password: password, }, nil } + +// StringInSlice determines if a string is in a string slice, returns bool +func StringInSlice(s string, sl []string) bool { + for _, i := range sl { + if i == s { + return true + } + } + return false +} diff --git a/pkg/util/utils_test.go b/pkg/util/utils_test.go new file mode 100644 index 000000000..f47c0b7ad --- /dev/null +++ b/pkg/util/utils_test.go @@ -0,0 +1,19 @@ +package util + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +var ( + sliceData = []string{"one", "two", "three", "four"} +) + +func TestStringInSlice(t *testing.T) { + // string is in the slice + assert.True(t, StringInSlice("one", sliceData)) + // string is not in the slice + assert.False(t, StringInSlice("five", sliceData)) + // string is not in empty slice + assert.False(t, StringInSlice("one", []string{})) +} -- cgit v1.2.3-54-g00ecf