1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/opts/secret_test.go
Aaron Lehmann e7c39f4d5d api: Remove SecretRequestOption type
This type is only used by CLI code. It duplicates SecretReference in the
types/swarm package. Change the CLI code to use that type instead.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-03-16 11:20:31 -07:00

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.SecretName, "app-secret")
assert.Equal(t, req.File.Name, "app-secret")
assert.Equal(t, req.File.UID, "0")
assert.Equal(t, req.File.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.SecretName, "foo")
assert.Equal(t, req.File.Name, "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.SecretName, "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.SecretName, "foo")
assert.Equal(t, req.File.Name, "testing")
assert.Equal(t, req.File.UID, "1000")
assert.Equal(t, req.File.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.SecretName, "foo")
assert.Equal(t, req.File.Name, "testing")
assert.Equal(t, req.File.UID, "1000")
assert.Equal(t, req.File.GID, "1001")
assert.Equal(t, req.File.Mode, os.FileMode(0444))
}