2016-06-17 15:42:16 -04:00
|
|
|
package swarm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/pkg/testutil/assert"
|
2016-06-17 16:02:04 -04:00
|
|
|
"github.com/docker/engine-api/types/swarm"
|
2016-06-17 15:42:16 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNodeAddrOptionSetHostAndPort(t *testing.T) {
|
2016-06-21 17:27:04 -04:00
|
|
|
opt := NewNodeAddrOption("old:123")
|
2016-06-17 15:42:16 -04:00
|
|
|
addr := "newhost:5555"
|
|
|
|
assert.NilError(t, opt.Set(addr))
|
|
|
|
assert.Equal(t, opt.Value(), addr)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNodeAddrOptionSetHostOnly(t *testing.T) {
|
|
|
|
opt := NewListenAddrOption()
|
|
|
|
assert.NilError(t, opt.Set("newhost"))
|
2016-06-21 17:27:04 -04:00
|
|
|
assert.Equal(t, opt.Value(), "newhost:2377")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNodeAddrOptionSetHostOnlyIPv6(t *testing.T) {
|
|
|
|
opt := NewListenAddrOption()
|
|
|
|
assert.NilError(t, opt.Set("::1"))
|
|
|
|
assert.Equal(t, opt.Value(), "[::1]:2377")
|
2016-06-17 15:42:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNodeAddrOptionSetPortOnly(t *testing.T) {
|
|
|
|
opt := NewListenAddrOption()
|
|
|
|
assert.NilError(t, opt.Set(":4545"))
|
2016-06-21 17:27:04 -04:00
|
|
|
assert.Equal(t, opt.Value(), "0.0.0.0:4545")
|
2016-06-17 15:42:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNodeAddrOptionSetInvalidFormat(t *testing.T) {
|
|
|
|
opt := NewListenAddrOption()
|
2016-06-21 17:27:04 -04:00
|
|
|
assert.Error(t, opt.Set("http://localhost:4545"), "Invalid")
|
2016-06-17 15:42:16 -04:00
|
|
|
}
|
2016-06-17 16:02:04 -04:00
|
|
|
|
|
|
|
func TestAutoAcceptOptionSetWorker(t *testing.T) {
|
|
|
|
opt := NewAutoAcceptOption()
|
|
|
|
assert.NilError(t, opt.Set("worker"))
|
2016-06-29 17:01:25 -04:00
|
|
|
assert.Equal(t, opt.isPresent(worker), true)
|
2016-06-17 16:02:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAutoAcceptOptionSetManager(t *testing.T) {
|
|
|
|
opt := NewAutoAcceptOption()
|
|
|
|
assert.NilError(t, opt.Set("manager"))
|
2016-06-29 17:01:25 -04:00
|
|
|
assert.Equal(t, opt.isPresent(manager), true)
|
2016-06-17 16:02:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAutoAcceptOptionSetInvalid(t *testing.T) {
|
|
|
|
opt := NewAutoAcceptOption()
|
2016-06-29 17:01:25 -04:00
|
|
|
assert.Error(t, opt.Set("bogus"), "must be one / combination")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAutoAcceptOptionSetEmpty(t *testing.T) {
|
|
|
|
opt := NewAutoAcceptOption()
|
|
|
|
assert.Error(t, opt.Set(""), "must be one / combination")
|
2016-06-17 16:02:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAutoAcceptOptionSetNone(t *testing.T) {
|
|
|
|
opt := NewAutoAcceptOption()
|
|
|
|
assert.NilError(t, opt.Set("none"))
|
2016-06-29 17:01:25 -04:00
|
|
|
assert.Equal(t, opt.isPresent(manager), false)
|
|
|
|
assert.Equal(t, opt.isPresent(worker), false)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAutoAcceptOptionSetTwo(t *testing.T) {
|
|
|
|
opt := NewAutoAcceptOption()
|
|
|
|
assert.NilError(t, opt.Set("worker,manager"))
|
|
|
|
assert.Equal(t, opt.isPresent(manager), true)
|
|
|
|
assert.Equal(t, opt.isPresent(worker), true)
|
2016-06-17 16:02:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAutoAcceptOptionSetConflict(t *testing.T) {
|
|
|
|
opt := NewAutoAcceptOption()
|
2016-06-29 17:01:25 -04:00
|
|
|
assert.Error(t, opt.Set("none,manager"), "value NONE cannot be specified alongside other node types")
|
2016-06-17 16:02:04 -04:00
|
|
|
|
|
|
|
opt = NewAutoAcceptOption()
|
2016-06-29 17:01:25 -04:00
|
|
|
assert.Error(t, opt.Set("none,worker"), "value NONE cannot be specified alongside other node types")
|
|
|
|
|
|
|
|
opt = NewAutoAcceptOption()
|
|
|
|
assert.Error(t, opt.Set("worker,none,manager"), "value NONE cannot be specified alongside other node types")
|
|
|
|
|
|
|
|
opt = NewAutoAcceptOption()
|
|
|
|
assert.Error(t, opt.Set("worker,manager,none"), "value NONE cannot be specified alongside other node types")
|
2016-06-17 16:02:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAutoAcceptOptionPoliciesDefault(t *testing.T) {
|
|
|
|
opt := NewAutoAcceptOption()
|
|
|
|
secret := "thesecret"
|
|
|
|
|
|
|
|
policies := opt.Policies(&secret)
|
|
|
|
assert.Equal(t, len(policies), 2)
|
|
|
|
assert.Equal(t, policies[0], swarm.Policy{
|
2016-06-29 17:01:25 -04:00
|
|
|
Role: worker,
|
2016-06-17 16:02:04 -04:00
|
|
|
Autoaccept: true,
|
|
|
|
Secret: &secret,
|
|
|
|
})
|
|
|
|
assert.Equal(t, policies[1], swarm.Policy{
|
2016-06-29 17:01:25 -04:00
|
|
|
Role: manager,
|
2016-06-17 16:02:04 -04:00
|
|
|
Autoaccept: false,
|
|
|
|
Secret: &secret,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAutoAcceptOptionPoliciesWithManager(t *testing.T) {
|
|
|
|
opt := NewAutoAcceptOption()
|
|
|
|
secret := "thesecret"
|
|
|
|
|
|
|
|
assert.NilError(t, opt.Set("manager"))
|
|
|
|
|
|
|
|
policies := opt.Policies(&secret)
|
|
|
|
assert.Equal(t, len(policies), 2)
|
|
|
|
assert.Equal(t, policies[0], swarm.Policy{
|
2016-06-29 17:01:25 -04:00
|
|
|
Role: worker,
|
2016-06-17 16:02:04 -04:00
|
|
|
Autoaccept: false,
|
|
|
|
Secret: &secret,
|
|
|
|
})
|
|
|
|
assert.Equal(t, policies[1], swarm.Policy{
|
2016-06-29 17:01:25 -04:00
|
|
|
Role: manager,
|
2016-06-17 16:02:04 -04:00
|
|
|
Autoaccept: true,
|
|
|
|
Secret: &secret,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAutoAcceptOptionString(t *testing.T) {
|
|
|
|
opt := NewAutoAcceptOption()
|
|
|
|
assert.NilError(t, opt.Set("manager"))
|
|
|
|
assert.NilError(t, opt.Set("worker"))
|
|
|
|
|
|
|
|
repr := opt.String()
|
|
|
|
assert.Contains(t, repr, "worker=true")
|
|
|
|
assert.Contains(t, repr, "manager=true")
|
|
|
|
}
|