diff options
author | Kunal Kushwaha <kushwaha_kunal_v7@lab.ntt.co.jp> | 2019-09-12 17:40:48 +0900 |
---|---|---|
committer | Kunal Kushwaha <kushwaha_kunal_v7@lab.ntt.co.jp> | 2019-09-27 17:17:12 +0900 |
commit | 21363a6442022fc9c6fd05e70a363915f24f27a5 (patch) | |
tree | 921339f28b7e631502041b68e556492839e68001 /pkg/util/utils_test.go | |
parent | ce31aa37d6ca4762f4a82274452e089024529444 (diff) | |
download | podman-21363a6442022fc9c6fd05e70a363915f24f27a5.tar.gz podman-21363a6442022fc9c6fd05e70a363915f24f27a5.tar.bz2 podman-21363a6442022fc9c6fd05e70a363915f24f27a5.zip |
syntax updated for podman import --change
currently, podman import change do not support syntax like
- KEY val
- KEY ["val"]
This adds support for both of these syntax along with KEY=val
Signed-off-by: Kunal Kushwaha <kunal.kushwaha@gmail.com>
Diffstat (limited to 'pkg/util/utils_test.go')
-rw-r--r-- | pkg/util/utils_test.go | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/pkg/util/utils_test.go b/pkg/util/utils_test.go index f47c0b7ad..c938dc592 100644 --- a/pkg/util/utils_test.go +++ b/pkg/util/utils_test.go @@ -1,8 +1,9 @@ package util import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) var ( @@ -17,3 +18,71 @@ func TestStringInSlice(t *testing.T) { // string is not in empty slice assert.False(t, StringInSlice("one", []string{})) } + +func TestParseChanges(t *testing.T) { + // CMD=/bin/sh + _, vals, err := ParseChanges("CMD=/bin/sh") + assert.EqualValues(t, []string{"/bin/sh"}, vals) + assert.NoError(t, err) + + // CMD [/bin/sh] + _, vals, err = ParseChanges("CMD [/bin/sh]") + assert.EqualValues(t, []string{"/bin/sh"}, vals) + assert.NoError(t, err) + + // CMD ["/bin/sh"] + _, vals, err = ParseChanges(`CMD ["/bin/sh"]`) + assert.EqualValues(t, []string{`"/bin/sh"`}, vals) + assert.NoError(t, err) + + // CMD ["/bin/sh","-c","ls"] + _, vals, err = ParseChanges(`CMD ["/bin/sh","c","ls"]`) + assert.EqualValues(t, []string{`"/bin/sh"`, `"c"`, `"ls"`}, vals) + assert.NoError(t, err) + + // CMD ["/bin/sh","arg-with,comma"] + _, vals, err = ParseChanges(`CMD ["/bin/sh","arg-with,comma"]`) + assert.EqualValues(t, []string{`"/bin/sh"`, `"arg-with`, `comma"`}, vals) + assert.NoError(t, err) + + // CMD "/bin/sh"] + _, _, err = ParseChanges(`CMD "/bin/sh"]`) + assert.Error(t, err) + assert.Equal(t, `invalid value "/bin/sh"]`, err.Error()) + + // CMD [bin/sh + _, _, err = ParseChanges(`CMD "/bin/sh"]`) + assert.Error(t, err) + assert.Equal(t, `invalid value "/bin/sh"]`, err.Error()) + + // CMD ["/bin /sh"] + _, _, err = ParseChanges(`CMD ["/bin /sh"]`) + assert.Error(t, err) + assert.Equal(t, `invalid value "/bin /sh"`, err.Error()) + + // CMD ["/bin/sh", "-c","ls"] whitespace between values + _, vals, err = ParseChanges(`CMD ["/bin/sh", "c","ls"]`) + assert.Error(t, err) + assert.Equal(t, `invalid value "c"`, err.Error()) + + // CMD? + _, _, err = ParseChanges(`CMD?`) + assert.Error(t, err) + assert.Equal(t, `invalid format CMD?`, err.Error()) + + // empty values for CMD + _, _, err = ParseChanges(`CMD `) + assert.Error(t, err) + assert.Equal(t, `invalid value `, err.Error()) + + // LABEL=blue=image + _, vals, err = ParseChanges(`LABEL=blue=image`) + assert.EqualValues(t, []string{"blue", "image"}, vals) + assert.NoError(t, err) + + // LABEL = blue=image + _, vals, err = ParseChanges(`LABEL = blue=image`) + assert.Error(t, err) + assert.Equal(t, `invalid value = blue=image`, err.Error()) + +} |