2018-03-06 10:32:47 -05:00
|
|
|
package opts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2018-03-11 11:52:12 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
2018-03-06 10:32:47 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSecretOptionsSimple(t *testing.T) {
|
|
|
|
var opt SecretOpt
|
|
|
|
|
|
|
|
testCase := "app-secret"
|
2018-03-11 11:52:12 -04:00
|
|
|
assert.NilError(t, opt.Set(testCase))
|
2018-03-06 10:32:47 -05:00
|
|
|
|
|
|
|
reqs := opt.Value()
|
2018-03-11 11:52:12 -04:00
|
|
|
assert.Assert(t, is.Len(reqs, 1))
|
2018-03-06 10:32:47 -05:00
|
|
|
req := reqs[0]
|
2018-03-11 11:52:12 -04:00
|
|
|
assert.Check(t, is.Equal("app-secret", req.SecretName))
|
|
|
|
assert.Check(t, is.Equal("app-secret", req.File.Name))
|
|
|
|
assert.Check(t, is.Equal("0", req.File.UID))
|
|
|
|
assert.Check(t, is.Equal("0", req.File.GID))
|
2018-03-06 10:32:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSecretOptionsSourceTarget(t *testing.T) {
|
|
|
|
var opt SecretOpt
|
|
|
|
|
|
|
|
testCase := "source=foo,target=testing"
|
2018-03-11 11:52:12 -04:00
|
|
|
assert.NilError(t, opt.Set(testCase))
|
2018-03-06 10:32:47 -05:00
|
|
|
|
|
|
|
reqs := opt.Value()
|
2018-03-11 11:52:12 -04:00
|
|
|
assert.Assert(t, is.Len(reqs, 1))
|
2018-03-06 10:32:47 -05:00
|
|
|
req := reqs[0]
|
2018-03-11 11:52:12 -04:00
|
|
|
assert.Check(t, is.Equal("foo", req.SecretName))
|
|
|
|
assert.Check(t, is.Equal("testing", req.File.Name))
|
2018-03-06 10:32:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSecretOptionsShorthand(t *testing.T) {
|
|
|
|
var opt SecretOpt
|
|
|
|
|
|
|
|
testCase := "src=foo,target=testing"
|
2018-03-11 11:52:12 -04:00
|
|
|
assert.NilError(t, opt.Set(testCase))
|
2018-03-06 10:32:47 -05:00
|
|
|
|
|
|
|
reqs := opt.Value()
|
2018-03-11 11:52:12 -04:00
|
|
|
assert.Assert(t, is.Len(reqs, 1))
|
2018-03-06 10:32:47 -05:00
|
|
|
req := reqs[0]
|
2018-03-11 11:52:12 -04:00
|
|
|
assert.Check(t, is.Equal("foo", req.SecretName))
|
2018-03-06 10:32:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSecretOptionsCustomUidGid(t *testing.T) {
|
|
|
|
var opt SecretOpt
|
|
|
|
|
|
|
|
testCase := "source=foo,target=testing,uid=1000,gid=1001"
|
2018-03-11 11:52:12 -04:00
|
|
|
assert.NilError(t, opt.Set(testCase))
|
2018-03-06 10:32:47 -05:00
|
|
|
|
|
|
|
reqs := opt.Value()
|
2018-03-11 11:52:12 -04:00
|
|
|
assert.Assert(t, is.Len(reqs, 1))
|
2018-03-06 10:32:47 -05:00
|
|
|
req := reqs[0]
|
2018-03-11 11:52:12 -04:00
|
|
|
assert.Check(t, is.Equal("foo", req.SecretName))
|
|
|
|
assert.Check(t, is.Equal("testing", req.File.Name))
|
|
|
|
assert.Check(t, is.Equal("1000", req.File.UID))
|
|
|
|
assert.Check(t, is.Equal("1001", req.File.GID))
|
2018-03-06 10:32:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSecretOptionsCustomMode(t *testing.T) {
|
|
|
|
var opt SecretOpt
|
|
|
|
|
|
|
|
testCase := "source=foo,target=testing,uid=1000,gid=1001,mode=0444"
|
2018-03-11 11:52:12 -04:00
|
|
|
assert.NilError(t, opt.Set(testCase))
|
2018-03-06 10:32:47 -05:00
|
|
|
|
|
|
|
reqs := opt.Value()
|
2018-03-11 11:52:12 -04:00
|
|
|
assert.Assert(t, is.Len(reqs, 1))
|
2018-03-06 10:32:47 -05:00
|
|
|
req := reqs[0]
|
2018-03-11 11:52:12 -04:00
|
|
|
assert.Check(t, is.Equal("foo", req.SecretName))
|
|
|
|
assert.Check(t, is.Equal("testing", req.File.Name))
|
|
|
|
assert.Check(t, is.Equal("1000", req.File.UID))
|
|
|
|
assert.Check(t, is.Equal("1001", req.File.GID))
|
|
|
|
assert.Check(t, is.Equal(os.FileMode(0444), req.File.Mode))
|
2018-03-06 10:32:47 -05:00
|
|
|
}
|