2016-11-03 15:56:05 -04:00
|
|
|
package opts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2018-03-05 18:53:52 -05:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
2016-11-03 15:56:05 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSecretOptionsSimple(t *testing.T) {
|
|
|
|
var opt SecretOpt
|
|
|
|
|
|
|
|
testCase := "app-secret"
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, opt.Set(testCase))
|
2016-11-03 15:56:05 -04:00
|
|
|
|
|
|
|
reqs := opt.Value()
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Assert(t, is.Len(reqs, 1))
|
2016-11-03 15:56:05 -04:00
|
|
|
req := reqs[0]
|
2018-03-05 18:53:52 -05: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))
|
2016-11-03 15:56:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSecretOptionsSourceTarget(t *testing.T) {
|
|
|
|
var opt SecretOpt
|
|
|
|
|
|
|
|
testCase := "source=foo,target=testing"
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, opt.Set(testCase))
|
2016-11-03 15:56:05 -04:00
|
|
|
|
|
|
|
reqs := opt.Value()
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Assert(t, is.Len(reqs, 1))
|
2016-11-03 15:56:05 -04:00
|
|
|
req := reqs[0]
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal("foo", req.SecretName))
|
|
|
|
assert.Check(t, is.Equal("testing", req.File.Name))
|
2016-11-03 15:56:05 -04:00
|
|
|
}
|
|
|
|
|
2017-01-24 09:41:45 -05:00
|
|
|
func TestSecretOptionsShorthand(t *testing.T) {
|
|
|
|
var opt SecretOpt
|
|
|
|
|
|
|
|
testCase := "src=foo,target=testing"
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, opt.Set(testCase))
|
2017-01-24 09:41:45 -05:00
|
|
|
|
|
|
|
reqs := opt.Value()
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Assert(t, is.Len(reqs, 1))
|
2017-01-24 09:41:45 -05:00
|
|
|
req := reqs[0]
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal("foo", req.SecretName))
|
2017-01-24 09:41:45 -05:00
|
|
|
}
|
|
|
|
|
2016-11-03 15:56:05 -04:00
|
|
|
func TestSecretOptionsCustomUidGid(t *testing.T) {
|
|
|
|
var opt SecretOpt
|
|
|
|
|
|
|
|
testCase := "source=foo,target=testing,uid=1000,gid=1001"
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, opt.Set(testCase))
|
2016-11-03 15:56:05 -04:00
|
|
|
|
|
|
|
reqs := opt.Value()
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Assert(t, is.Len(reqs, 1))
|
2016-11-03 15:56:05 -04:00
|
|
|
req := reqs[0]
|
2018-03-05 18:53:52 -05: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))
|
2016-11-03 15:56:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSecretOptionsCustomMode(t *testing.T) {
|
|
|
|
var opt SecretOpt
|
|
|
|
|
|
|
|
testCase := "source=foo,target=testing,uid=1000,gid=1001,mode=0444"
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, opt.Set(testCase))
|
2016-11-03 15:56:05 -04:00
|
|
|
|
|
|
|
reqs := opt.Value()
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Assert(t, is.Len(reqs, 1))
|
2016-11-03 15:56:05 -04:00
|
|
|
req := reqs[0]
|
2018-03-05 18:53:52 -05: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))
|
2016-11-03 15:56:05 -04:00
|
|
|
}
|