github.com/kunnos/engine@v1.13.1/cli/command/swarm/opts_test.go (about)

     1  package swarm
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/docker/docker/pkg/testutil/assert"
     7  )
     8  
     9  func TestNodeAddrOptionSetHostAndPort(t *testing.T) {
    10  	opt := NewNodeAddrOption("old:123")
    11  	addr := "newhost:5555"
    12  	assert.NilError(t, opt.Set(addr))
    13  	assert.Equal(t, opt.Value(), addr)
    14  }
    15  
    16  func TestNodeAddrOptionSetHostOnly(t *testing.T) {
    17  	opt := NewListenAddrOption()
    18  	assert.NilError(t, opt.Set("newhost"))
    19  	assert.Equal(t, opt.Value(), "newhost:2377")
    20  }
    21  
    22  func TestNodeAddrOptionSetHostOnlyIPv6(t *testing.T) {
    23  	opt := NewListenAddrOption()
    24  	assert.NilError(t, opt.Set("::1"))
    25  	assert.Equal(t, opt.Value(), "[::1]:2377")
    26  }
    27  
    28  func TestNodeAddrOptionSetPortOnly(t *testing.T) {
    29  	opt := NewListenAddrOption()
    30  	assert.NilError(t, opt.Set(":4545"))
    31  	assert.Equal(t, opt.Value(), "0.0.0.0:4545")
    32  }
    33  
    34  func TestNodeAddrOptionSetInvalidFormat(t *testing.T) {
    35  	opt := NewListenAddrOption()
    36  	assert.Error(t, opt.Set("http://localhost:4545"), "Invalid")
    37  }