mirror of https://github.com/docker/cli.git
Opts lint issues, ip and ulimit
Signed-off-by: Sevki Hasirci <s@sevki.org>
This commit is contained in:
parent
f2934dbacf
commit
409920de5c
17
opts/ip.go
17
opts/ip.go
|
@ -5,20 +5,23 @@ import (
|
|||
"net"
|
||||
)
|
||||
|
||||
// IpOpt type that hold an IP
|
||||
type IpOpt struct {
|
||||
// IPOpt type that hold an IP
|
||||
type IPOpt struct {
|
||||
*net.IP
|
||||
}
|
||||
|
||||
func NewIpOpt(ref *net.IP, defaultVal string) *IpOpt {
|
||||
o := &IpOpt{
|
||||
// NewIPOpt returns a new IPOpt from a string of an IP.
|
||||
func NewIPOpt(ref *net.IP, defaultVal string) *IPOpt {
|
||||
o := &IPOpt{
|
||||
IP: ref,
|
||||
}
|
||||
o.Set(defaultVal)
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *IpOpt) Set(val string) error {
|
||||
// Set sets an IPv4 or IPv6 address from a given string. If the given
|
||||
// string is not parsable as an IP address it will return an error.
|
||||
func (o *IPOpt) Set(val string) error {
|
||||
ip := net.ParseIP(val)
|
||||
if ip == nil {
|
||||
return fmt.Errorf("%s is not an ip address", val)
|
||||
|
@ -27,7 +30,9 @@ func (o *IpOpt) Set(val string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (o *IpOpt) String() string {
|
||||
// String returns the IP address stored in the IPOpt. If IPOpt is a
|
||||
// nil pointer, it returns an empty string.
|
||||
func (o *IPOpt) String() string {
|
||||
if *o.IP == nil {
|
||||
return ""
|
||||
}
|
||||
|
|
|
@ -45,9 +45,9 @@ func TestIpOptSetInvalidVal(t *testing.T) {
|
|||
ip := net.IPv4(127, 0, 0, 1)
|
||||
ipOpt := &IpOpt{IP: &ip}
|
||||
|
||||
invalidIp := "invalid ip"
|
||||
invalidIP := "invalid ip"
|
||||
expectedError := "invalid ip is not an ip address"
|
||||
err := ipOpt.Set(invalidIp)
|
||||
err := ipOpt.Set(invalidIP)
|
||||
if err == nil || err.Error() != expectedError {
|
||||
t.Fatalf("Expected an Error with [%v], got [%v]", expectedError, err.Error())
|
||||
}
|
||||
|
|
|
@ -6,10 +6,12 @@ import (
|
|||
"github.com/docker/docker/pkg/ulimit"
|
||||
)
|
||||
|
||||
// UlimitOpt defines a map of Ulimits
|
||||
type UlimitOpt struct {
|
||||
values *map[string]*ulimit.Ulimit
|
||||
}
|
||||
|
||||
// NewUlimitOpt creates a new UlimitOpt
|
||||
func NewUlimitOpt(ref *map[string]*ulimit.Ulimit) *UlimitOpt {
|
||||
if ref == nil {
|
||||
ref = &map[string]*ulimit.Ulimit{}
|
||||
|
@ -17,6 +19,7 @@ func NewUlimitOpt(ref *map[string]*ulimit.Ulimit) *UlimitOpt {
|
|||
return &UlimitOpt{ref}
|
||||
}
|
||||
|
||||
// Set validates a Ulimit and sets its name as a key in UlimitOpt
|
||||
func (o *UlimitOpt) Set(val string) error {
|
||||
l, err := ulimit.Parse(val)
|
||||
if err != nil {
|
||||
|
@ -28,6 +31,7 @@ func (o *UlimitOpt) Set(val string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// String returns Ulimit values as a string.
|
||||
func (o *UlimitOpt) String() string {
|
||||
var out []string
|
||||
for _, v := range *o.values {
|
||||
|
@ -37,6 +41,7 @@ func (o *UlimitOpt) String() string {
|
|||
return fmt.Sprintf("%v", out)
|
||||
}
|
||||
|
||||
// GetList returns a slice of pointers to Ulimits.
|
||||
func (o *UlimitOpt) GetList() []*ulimit.Ulimit {
|
||||
var ulimits []*ulimit.Ulimit
|
||||
for _, v := range *o.values {
|
||||
|
|
Loading…
Reference in New Issue