214f42d541
This patch adds a "src" alias for `--secret`
to be consistent with `--mount`.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 950658bbb6
)
Signed-off-by: Victor Vieux <vieux@docker.com>
79 lines
1.8 KiB
Go
79 lines
1.8 KiB
Go
package opts
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/docker/docker/pkg/testutil/assert"
|
|
)
|
|
|
|
func TestSecretOptionsSimple(t *testing.T) {
|
|
var opt SecretOpt
|
|
|
|
testCase := "app-secret"
|
|
assert.NilError(t, opt.Set(testCase))
|
|
|
|
reqs := opt.Value()
|
|
assert.Equal(t, len(reqs), 1)
|
|
req := reqs[0]
|
|
assert.Equal(t, req.Source, "app-secret")
|
|
assert.Equal(t, req.Target, "app-secret")
|
|
assert.Equal(t, req.UID, "0")
|
|
assert.Equal(t, req.GID, "0")
|
|
}
|
|
|
|
func TestSecretOptionsSourceTarget(t *testing.T) {
|
|
var opt SecretOpt
|
|
|
|
testCase := "source=foo,target=testing"
|
|
assert.NilError(t, opt.Set(testCase))
|
|
|
|
reqs := opt.Value()
|
|
assert.Equal(t, len(reqs), 1)
|
|
req := reqs[0]
|
|
assert.Equal(t, req.Source, "foo")
|
|
assert.Equal(t, req.Target, "testing")
|
|
}
|
|
|
|
func TestSecretOptionsShorthand(t *testing.T) {
|
|
var opt SecretOpt
|
|
|
|
testCase := "src=foo,target=testing"
|
|
assert.NilError(t, opt.Set(testCase))
|
|
|
|
reqs := opt.Value()
|
|
assert.Equal(t, len(reqs), 1)
|
|
req := reqs[0]
|
|
assert.Equal(t, req.Source, "foo")
|
|
}
|
|
|
|
func TestSecretOptionsCustomUidGid(t *testing.T) {
|
|
var opt SecretOpt
|
|
|
|
testCase := "source=foo,target=testing,uid=1000,gid=1001"
|
|
assert.NilError(t, opt.Set(testCase))
|
|
|
|
reqs := opt.Value()
|
|
assert.Equal(t, len(reqs), 1)
|
|
req := reqs[0]
|
|
assert.Equal(t, req.Source, "foo")
|
|
assert.Equal(t, req.Target, "testing")
|
|
assert.Equal(t, req.UID, "1000")
|
|
assert.Equal(t, req.GID, "1001")
|
|
}
|
|
|
|
func TestSecretOptionsCustomMode(t *testing.T) {
|
|
var opt SecretOpt
|
|
|
|
testCase := "source=foo,target=testing,uid=1000,gid=1001,mode=0444"
|
|
assert.NilError(t, opt.Set(testCase))
|
|
|
|
reqs := opt.Value()
|
|
assert.Equal(t, len(reqs), 1)
|
|
req := reqs[0]
|
|
assert.Equal(t, req.Source, "foo")
|
|
assert.Equal(t, req.Target, "testing")
|
|
assert.Equal(t, req.UID, "1000")
|
|
assert.Equal(t, req.GID, "1001")
|
|
assert.Equal(t, req.Mode, os.FileMode(0444))
|
|
}
|