mirror of https://github.com/docker/docs.git
adding ip as an option for flags
Signed-off-by: Isabel Jimenez <contact.isabeljimenez@gmail.com>
This commit is contained in:
parent
19d51f4a1a
commit
8001455ecf
|
@ -1,6 +1,7 @@
|
|||
package cluster
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -49,3 +50,11 @@ func (do DriverOpts) Float(key, env string) (float64, bool) {
|
|||
}
|
||||
return 0.0, false
|
||||
}
|
||||
|
||||
// IP returns an IP address from the driver options
|
||||
func (do DriverOpts) IP(key, env string) (net.IP, bool) {
|
||||
if value, ok := do.String(key, env); ok {
|
||||
return net.ParseIP(value), true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package cluster
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var opts = DriverOpts{"foo1=bar", "foo2=-5", "foo3=7", "foo4=0.6"}
|
||||
var opts = DriverOpts{"foo1=bar", "foo2=-5", "foo3=7", "foo4=0.6", "foo5=127.0.0.1"}
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
os.Setenv("FOO_4", "bar")
|
||||
|
@ -125,3 +126,20 @@ func TestFloat(t *testing.T) {
|
|||
assert.False(t, ok)
|
||||
assert.Equal(t, val, 0.0)
|
||||
}
|
||||
|
||||
func TestIP(t *testing.T) {
|
||||
os.Setenv("FOO_4", "0.0.0.0")
|
||||
defer os.Setenv("FOO_4", "")
|
||||
|
||||
val, ok := opts.IP("foo5", "")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, val, net.ParseIP("127.0.0.1"))
|
||||
|
||||
val, ok = opts.IP("", "FOO_4")
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, val, net.ParseIP("0.0.0.0"))
|
||||
|
||||
val, ok = opts.IP("invalid", "")
|
||||
assert.False(t, ok)
|
||||
assert.Equal(t, val, net.IP(nil))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue